* @class
* @extends PIXI.Filter
* @memberof PIXI.filters
*/
var ColorMatrixFilter = /** @class */ (function (_super) {
__extends$6(ColorMatrixFilter, _super);
function ColorMatrixFilter() {
var _this = this;
var uniforms = {
m: new Float32Array([1, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0]),
uAlpha: 1,
};
_this = _super.call(this, defaultFilter, fragment$4, uniforms) || this;
_this.alpha = 1;
return _this;
}
/**
* Transforms current matrix and set the new one
*
* @param {number[]} matrix - 5x4 matrix
* @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
* just set the current matrix with @param matrix
*/
ColorMatrixFilter.prototype._loadMatrix = function (matrix, multiply) {
if (multiply === void 0) { multiply = false; }
var newMatrix = matrix;
if (multiply) {
this._multiply(newMatrix, this.uniforms.m, matrix);
newMatrix = this._colorMatrix(newMatrix);
}
// set the new matrix
this.uniforms.m = newMatrix;
};
/**
* Multiplies two mat5's
*
* @private
* @param {number[]} out - 5x4 matrix the receiving matrix
* @param {number[]} a - 5x4 matrix the first operand
* @param {number[]} b - 5x4 matrix the second operand
* @returns {number[]} 5x4 matrix
*/
ColorMatrixFilter.prototype._multiply = function (out, a, b) {
// Red Channel
out[0] = (a[0] * b[0]) + (a[1] * b[5]) + (a[2] * b[10]) + (a[3] * b[15]);
out[1] = (a[0] * b[1]) + (a[1] * b[6]) + (a[2] * b[11]) + (a[3] * b[16]);
out[2] = (a[0] * b[2]) + (a[1] * b[7]) + (a[2] * b[12]) + (a[3] * b[17]);
out[3] = (a[0] * b[3]) + (a[1] * b[8]) + (a[2] * b[13]) + (a[3] * b[18]);
out[4] = (a[0] * b[4]) + (a[1] * b[9]) + (a[2] * b[14]) + (a[3] * b[19]) + a[4];
// Green Channel
out[5] = (a[5] * b[0]) + (a[6] * b[5]) + (a[7] * b[10]) + (a[8] * b[15]);
out[6] = (a[5] * b[1]) + (a[6] * b[6]) + (a[7] * b[11]) + (a[8] * b[16]);
out[7] = (a[5] * b[2]) + (a[6] * b[7]) + (a[7] * b[12]) + (a[8] * b[17]);
out[8] = (a[5] * b[3]) + (a[6] * b[8]) + (a[7] * b[13]) + (a[8] * b[18]);
out[9] = (a[5] * b[4]) + (a[6] * b[9]) + (a[7] * b[14]) + (a[8] * b[19]) + a[9];
// Blue Channel
out[10] = (a[10] * b[0]) + (a[11] * b[5]) + (a[12] * b[10]) + (a[13] * b[15]);
out[11] = (a[10] * b[1]) + (a[11] * b[6]) + (a[12] * b[11]) + (a[13] * b[16]);
out[12] = (a[10] * b[2]) + (a[11] * b[7]) + (a[12] * b[12]) + (a[13] * b[17]);
out[13] = (a[10] * b[3]) + (a[11] * b[8]) + (a[12] * b[13]) + (a[13] * b[18]);
out[14] = (a[10] * b[4]) + (a[11] * b[9]) + (a[12] * b[14]) + (a[13] * b[19]) + a[14];
// Alpha Channel
out[15] = (a[15] * b[0]) + (a[16] * b[5]) + (a[17] * b[10]) + (a[18] * b[15]);
out[16] = (a[15] * b[1]) + (a[16] * b[6]) + (a[17] * b[11]) + (a[18] * b[16]);
out[17] = (a[15] * b[2]) + (a[16] * b[7]) + (a[17] * b[12]) + (a[18] * b[17]);
out[18] = (a[15] * b[3]) + (a[16] * b[8]) + (a[17] * b[13]) + (a[18] * b[18]);
out[19] = (a[15] * b[4]) + (a[16] * b[9]) + (a[17] * b[14]) + (a[18] * b[19]) + a[19];
return out;
};
/**
* Create a Float32 Array and normalize the offset component to 0-1
*
* @private
* @param {number[]} matrix - 5x4 matrix
* @return {number[]} 5x4 matrix with all values between 0-1
*/
ColorMatrixFilter.prototype._colorMatrix = function (matrix) {
// Create a Float32 Array and normalize the offset component to 0-1
var m = new Float32Array(matrix);
m[4] /= 255;
m[9] /= 255;
m[14] /= 255;
m[19] /= 255;
return m;
};
/**
* Adjusts brightness
*
* @param {number} b - value of the brigthness (0-1, where 0 is black)
* @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
* just set the current matrix with @param matrix
*/
ColorMatrixFilter.prototype.brightness = function (b, multiply) {
var matrix = [
b, 0, 0, 0, 0,
0, b, 0, 0, 0,
0, 0, b, 0, 0,
0, 0, 0, 1, 0 ];
this._loadMatrix(matrix, multiply);
};
/**
* Set the matrices in grey scales
*
* @param {number} scale - value of the grey (0-1, where 0 is black)
* @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
* just set the current matrix with @param matrix
*/
ColorMatrixFilter.prototype.greyscale = function (scale, multiply) {
var matrix = [
scale, scale, scale, 0, 0,
scale, scale, scale, 0, 0,
scale, scale, scale, 0, 0,
0, 0, 0, 1, 0 ];
this._loadMatrix(matrix, multiply);
};
/**
* Set the black and white matrice.
*
* @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
* just set the current matrix with @param matrix
*/
ColorMatrixFilter.prototype.blackAndWhite = function (multiply) {
var matrix = [
0.3, 0.6, 0.1, 0, 0,
0.3, 0.6, 0.1, 0, 0,
0.3, 0.6, 0.1, 0, 0,
0, 0, 0, 1, 0 ];
this._loadMatrix(matrix, multiply);
};
/**
* Set the hue property of the color
*
* @param {number} rotation - in degrees
* @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
* just set the current matrix with @param matrix
*/
ColorMatrixFilter.prototype.hue = function (rotation, multiply) {
rotation = (rotation || 0) / 180 * Math.PI;
var cosR = Math.cos(rotation);
var sinR = Math.sin(rotation);
var sqrt = Math.sqrt;
/* a good approximation for hue rotation
This matrix is far better than the versions with magic luminance constants
formerly used here, but also used in the starling framework (flash) and known from this
old part of the internet: quasimondo.com/archives/000565.php
This new matrix is based on rgb cube rotation in space. Look here for a more descriptive
implementation as a shader not a general matrix:
https://github.com/evanw/glfx.js/blob/58841c23919bd59787effc0333a4897b43835412/src/filters/adjust/huesaturation.js
This is the source for the code:
see http://stackoverflow.com/questions/8507885/shift-hue-of-an-rgb-color/8510751#8510751
*/
var w = 1 / 3;
var sqrW = sqrt(w); // weight is
var a00 = cosR + ((1.0 - cosR) * w);
var a01 = (w * (1.0 - cosR)) - (sqrW * sinR);
var a02 = (w * (1.0 - cosR)) + (sqrW * sinR);
var a10 = (w * (1.0 - cosR)) + (sqrW * sinR);
var a11 = cosR + (w * (1.0 - cosR));
var a12 = (w * (1.0 - cosR)) - (sqrW * sinR);
var a20 = (w * (1.0 - cosR)) - (sqrW * sinR);
var a21 = (w * (1.0 - cosR)) + (sqrW * sinR);
var a22 = cosR + (w * (1.0 - cosR));
var matrix = [
a00, a01, a02, 0, 0,
a10, a11, a12, 0, 0,
a20, a21, a22, 0, 0,
0, 0, 0, 1, 0 ];
this._loadMatrix(matrix, multiply);
};
/**
* Set the contrast matrix, increase the separation between dark and bright
* Increase contrast : shadows darker and highlights brighter
* Decrease contrast : bring the shadows up and the highlights down
*
* @param {number} amount - value of the contrast (0-1)
* @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
* just set the current matrix with @param matrix
*/
ColorMatrixFilter.prototype.contrast = function (amount, multiply) {
var v = (amount || 0) + 1;
var o = -0.5 * (v - 1);
var matrix = [
v, 0, 0, 0, o,
0, v, 0, 0, o,
0, 0, v, 0, o,
0, 0, 0, 1, 0 ];
this._loadMatrix(matrix, multiply);
};
/**
* Set the saturation matrix, increase the separation between colors
* Increase saturation : increase contrast, brightness, and sharpness
*
* @param {number} amount - The saturation amount (0-1)
* @param {boolean} [multiply] - if true, current matrix and matrix are multiplied. If false,
* just set the current matrix with @param matrix
*/
ColorMatrixFilter.prototype.saturate = function (amount, multiply) {
if (amount === void 0) { amount = 0; }
var x = (amount * 2 / 3) + 1;
var y = ((x - 1) * -0.5);
var matrix = [
x, y, y, 0, 0,
y, x, y, 0, 0,
y, y, x, 0, 0,
0, 0, 0, 1, 0 ];
this._loadMatrix(matrix, multiply);
};
/**
* Desaturate image (remove color)
*
* Call the saturate function
*
*/
ColorMatrixFilter.prototype.desaturate = function () {
this.saturate(-1);
};
/**
* Negative image (inverse of classic rgb matrix)
*
* @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
* just set the current matrix with @param matrix
*/
ColorMatrixFilter.prototype.negative = function (multiply) {
var matrix = [
-1, 0, 0, 1, 0,
0, -1, 0, 1, 0,
0, 0, -1, 1, 0,
0, 0, 0, 1, 0 ];
this._loadMatrix(matrix, multiply);
};
/**
* Sepia image
*
* @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
* just set the current matrix with @param matrix
*/
ColorMatrixFilter.prototype.sepia = function (multiply) {
var matrix = [
0.393, 0.7689999, 0.18899999, 0, 0,
0.349, 0.6859999, 0.16799999, 0, 0,
0.272, 0.5339999, 0.13099999, 0, 0,
0, 0, 0, 1, 0 ];
this._loadMatrix(matrix, multiply);
};
/**
* Color motion picture process invented in 1916 (thanks Dominic Szablewski)
*
* @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
* just set the current matrix with @param matrix
*/
ColorMatrixFilter.prototype.technicolor = function (multiply) {
var matrix = [
1.9125277891456083, -0.8545344976951645, -0.09155508482755585, 0, 11.793603434377337,
-0.3087833385928097, 1.7658908555458428, -0.10601743074722245, 0, -70.35205161461398,
-0.231103377548616, -0.7501899197440212, 1.847597816108189, 0, 30.950940869491138,
0, 0, 0, 1, 0 ];
this._loadMatrix(matrix, multiply);
};
/**
* Polaroid filter
*
* @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
* just set the current matrix with @param matrix
*/
ColorMatrixFilter.prototype.polaroid = function (multiply) {
var matrix = [
1.438, -0.062, -0.062, 0, 0,
-0.122, 1.378, -0.122, 0, 0,
-0.016, -0.016, 1.483, 0, 0,
0, 0, 0, 1, 0 ];
this._loadMatrix(matrix, multiply);
};
/**
* Filter who transforms : Red -> Blue and Blue -> Red
*
* @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
* just set the current matrix with @param matrix
*/
ColorMatrixFilter.prototype.toBGR = function (multiply) {
var matrix = [
0, 0, 1, 0, 0,
0, 1, 0, 0, 0,
1, 0, 0, 0, 0,
0, 0, 0, 1, 0 ];
this._loadMatrix(matrix, multiply);
};
/**
* Color reversal film introduced by Eastman Kodak in 1935. (thanks Dominic Szablewski)
*
* @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
* just set the current matrix with @param matrix
*/
ColorMatrixFilter.prototype.kodachrome = function (multiply) {
var matrix = [
1.1285582396593525, -0.3967382283601348, -0.03992559172921793, 0, 63.72958762196502,
-0.16404339962244616, 1.0835251566291304, -0.05498805115633132, 0, 24.732407896706203,
-0.16786010706155763, -0.5603416277695248, 1.6014850761964943, 0, 35.62982807460946,
0, 0, 0, 1, 0 ];
this._loadMatrix(matrix, multiply);
};
/**
* Brown delicious browni filter (thanks Dominic Szablewski)
*
* @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
* just set the current matrix with @param matrix
*/
ColorMatrixFilter.prototype.browni = function (multiply) {
var matrix = [
0.5997023498159715, 0.34553243048391263, -0.2708298674538042, 0, 47.43192855600873,
-0.037703249837783157, 0.8609577587992641, 0.15059552388459913, 0, -36.96841498319127,
0.24113635128153335, -0.07441037908422492, 0.44972182064877153, 0, -7.562075277591283,
0, 0, 0, 1, 0 ];
this._loadMatrix(matrix, multiply);
};
/**
* Vintage filter (thanks Dominic Szablewski)
*
* @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
* just set the current matrix with @param matrix
*/
ColorMatrixFilter.prototype.vintage = function (multiply) {
var matrix = [
0.6279345635605994, 0.3202183420819367, -0.03965408211312453, 0, 9.651285835294123,
0.02578397704808868, 0.6441188644374771, 0.03259127616149294, 0, 7.462829176470591,
0.0466055556782719, -0.0851232987247891, 0.5241648018700465, 0, 5.159190588235296,
0, 0, 0, 1, 0 ];
this._loadMatrix(matrix, multiply);
};
/**
* We don't know exactly what it does, kind of gradient map, but funny to play with!
*
* @param {number} desaturation - Tone values.
* @param {number} toned - Tone values.
* @param {number} lightColor - Tone values, example: `0xFFE580`
* @param {number} darkColor - Tone values, example: `0xFFE580`
* @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
* just set the current matrix with @param matrix
*/
ColorMatrixFilter.prototype.colorTone = function (desaturation, toned, lightColor, darkColor, multiply) {
desaturation = desaturation || 0.2;
toned = toned || 0.15;
lightColor = lightColor || 0xFFE580;
darkColor = darkColor || 0x338000;
var lR = ((lightColor >> 16) & 0xFF) / 255;
var lG = ((lightColor >> 8) & 0xFF) / 255;
var lB = (lightColor & 0xFF) / 255;
var dR = ((darkColor >> 16) & 0xFF) / 255;
var dG = ((darkColor >> 8) & 0xFF) / 255;
var dB = (darkColor & 0xFF) / 255;
var matrix = [
0.3, 0.59, 0.11, 0, 0,
lR, lG, lB, desaturation, 0,
dR, dG, dB, toned, 0,
lR - dR, lG - dG, lB - dB, 0, 0 ];
this._loadMatrix(matrix, multiply);
};
/**
* Night effect
*
* @param {number} intensity - The intensity of the night effect.
* @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
* just set the current matrix with @param matrix
*/
ColorMatrixFilter.prototype.night = function (intensity, multiply) {
intensity = intensity || 0.1;
var matrix = [
intensity * (-2.0), -intensity, 0, 0, 0,
-intensity, 0, intensity, 0, 0,
0, intensity, intensity * 2.0, 0, 0,
0, 0, 0, 1, 0 ];
this._loadMatrix(matrix, multiply);
};
/**
* Predator effect
*
* Erase the current matrix by setting a new indepent one
*
* @param {number} amount - how much the predator feels his future victim
* @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
* just set the current matrix with @param matrix
*/
ColorMatrixFilter.prototype.predator = function (amount, multiply) {
var matrix = [
// row 1
11.224130630493164 * amount,
-4.794486999511719 * amount,
-2.8746118545532227 * amount,
0 * amount,
0.40342438220977783 * amount,
// row 2
-3.6330697536468506 * amount,
9.193157196044922 * amount,
-2.951810836791992 * amount,
0 * amount,
-1.316135048866272 * amount,
// row 3
-3.2184197902679443 * amount,
-4.2375030517578125 * amount,
7.476448059082031 * amount,
0 * amount,
0.8044459223747253 * amount,
// row 4
0, 0, 0, 1, 0 ];
this._loadMatrix(matrix, multiply);
};
/**
* LSD effect
*
* Multiply the current matrix
*
* @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
* just set the current matrix with @param matrix
*/
ColorMatrixFilter.prototype.lsd = function (multiply) {
var matrix = [
2, -0.4, 0.5, 0, 0,
-0.5, 2, -0.4, 0, 0,
-0.4, -0.5, 3, 0, 0,
0, 0, 0, 1, 0 ];
this._loadMatrix(matrix, multiply);
};
/**
* Erase the current matrix by setting the default one
*
*/
ColorMatrixFilter.prototype.reset = function () {
var matrix = [
1, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0 ];
this._loadMatrix(matrix, false);
};
Object.defineProperty(ColorMatrixFilter.prototype, "matrix", {
/**
* The matrix of the color matrix filter
*
* @member {number[]}
* @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]
*/
get: function () {
return this.uniforms.m;
},
set: function (value) {
this.uniforms.m = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ColorMatrixFilter.prototype, "alpha", {
/**
* The opacity value to use when mixing the original and resultant colors.
*
* When the value is 0, the original color is used without modification.
* When the value is 1, the result color is used.
* When in the range (0, 1) the color is interpolated between the original and result by this amount.
*
* @member {number}
* @default 1
*/
get: function () {
return this.uniforms.uAlpha;
},
set: function (value) {
this.uniforms.uAlpha = value;
},
enumerable: true,
configurable: true
});
return ColorMatrixFilter;
}(Filter));
// Americanized alias
ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale;
/*!
* @pixi/filter-displacement - v5.2.1
* Compiled Tue, 04 Feb 2020 21:48:29 UTC
*
* @pixi/filter-displacement is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
*/
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics$7 = function(d, b) {
extendStatics$7 = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
return extendStatics$7(d, b);
};
function __extends$7(d, b) {
extendStatics$7(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
/**
* Two Pi.
*
* @static
* @constant {number} PI_2
* @memberof PIXI
*/
var PI_2$1 = Math.PI * 2;
/**
* Conversion factor for converting radians to degrees.
*
* @static
* @constant {number} RAD_TO_DEG
* @memberof PIXI
*/
var RAD_TO_DEG$1 = 180 / Math.PI;
/**
* Conversion factor for converting degrees to radians.
*
* @static
* @constant {number} DEG_TO_RAD
* @memberof PIXI
*/
var DEG_TO_RAD$1 = Math.PI / 180;
var SHAPES;
(function (SHAPES) {
SHAPES[SHAPES["POLY"] = 0] = "POLY";
SHAPES[SHAPES["RECT"] = 1] = "RECT";
SHAPES[SHAPES["CIRC"] = 2] = "CIRC";
SHAPES[SHAPES["ELIP"] = 3] = "ELIP";
SHAPES[SHAPES["RREC"] = 4] = "RREC";
})(SHAPES || (SHAPES = {}));
/**
* Constants that identify shapes, mainly to prevent `instanceof` calls.
*
* @static
* @constant
* @name SHAPES
* @memberof PIXI
* @type {enum}
* @property {number} POLY Polygon
* @property {number} RECT Rectangle
* @property {number} CIRC Circle
* @property {number} ELIP Ellipse
* @property {number} RREC Rounded Rectangle
* @enum {number}
*/
/**
* Size object, contains width and height
*
* @memberof PIXI
* @typedef {object} ISize
* @property {number} width - Width component
* @property {number} height - Height component
*/
/**
* Rectangle object is an area defined by its position, as indicated by its top-left corner
* point (x, y) and by its width and its height.
*
* @class
* @memberof PIXI
*/
var Rectangle$1 = /** @class */ (function () {
/**
* @param {number} [x=0] - The X coordinate of the upper-left corner of the rectangle
* @param {number} [y=0] - The Y coordinate of the upper-left corner of the rectangle
* @param {number} [width=0] - The overall width of this rectangle
* @param {number} [height=0] - The overall height of this rectangle
*/
function Rectangle(x, y, width, height) {
if (x === void 0) { x = 0; }
if (y === void 0) { y = 0; }
if (width === void 0) { width = 0; }
if (height === void 0) { height = 0; }
/**
* @member {number}
* @default 0
*/
this.x = Number(x);
/**
* @member {number}
* @default 0
*/
this.y = Number(y);
/**
* @member {number}
* @default 0
*/
this.width = Number(width);
/**
* @member {number}
* @default 0
*/
this.height = Number(height);
/**
* The type of the object, mainly used to avoid `instanceof` checks
*
* @member {number}
* @readOnly
* @default PIXI.SHAPES.RECT
* @see PIXI.SHAPES
*/
this.type = SHAPES.RECT;
}
Object.defineProperty(Rectangle.prototype, "left", {
/**
* returns the left edge of the rectangle
*
* @member {number}
*/
get: function () {
return this.x;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Rectangle.prototype, "right", {
/**
* returns the right edge of the rectangle
*
* @member {number}
*/
get: function () {
return this.x + this.width;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Rectangle.prototype, "top", {
/**
* returns the top edge of the rectangle
*
* @member {number}
*/
get: function () {
return this.y;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Rectangle.prototype, "bottom", {
/**
* returns the bottom edge of the rectangle
*
* @member {number}
*/
get: function () {
return this.y + this.height;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Rectangle, "EMPTY", {
/**
* A constant empty rectangle.
*
* @static
* @constant
* @member {PIXI.Rectangle}
* @return {PIXI.Rectangle} An empty rectangle
*/
get: function () {
return new Rectangle(0, 0, 0, 0);
},
enumerable: true,
configurable: true
});
/**
* Creates a clone of this Rectangle
*
* @return {PIXI.Rectangle} a copy of the rectangle
*/
Rectangle.prototype.clone = function () {
return new Rectangle(this.x, this.y, this.width, this.height);
};
/**
* Copies another rectangle to this one.
*
* @param {PIXI.Rectangle} rectangle - The rectangle to copy from.
* @return {PIXI.Rectangle} Returns itself.
*/
Rectangle.prototype.copyFrom = function (rectangle) {
this.x = rectangle.x;
this.y = rectangle.y;
this.width = rectangle.width;
this.height = rectangle.height;
return this;
};
/**
* Copies this rectangle to another one.
*
* @param {PIXI.Rectangle} rectangle - The rectangle to copy to.
* @return {PIXI.Rectangle} Returns given parameter.
*/
Rectangle.prototype.copyTo = function (rectangle) {
rectangle.x = this.x;
rectangle.y = this.y;
rectangle.width = this.width;
rectangle.height = this.height;
return rectangle;
};
/**
* Checks whether the x and y coordinates given are contained within this Rectangle
*
* @param {number} x - The X coordinate of the point to test
* @param {number} y - The Y coordinate of the point to test
* @return {boolean} Whether the x/y coordinates are within this Rectangle
*/
Rectangle.prototype.contains = function (x, y) {
if (this.width <= 0 || this.height <= 0) {
return false;
}
if (x >= this.x && x < this.x + this.width) {
if (y >= this.y && y < this.y + this.height) {
return true;
}
}
return false;
};
/**
* Pads the rectangle making it grow in all directions.
* If paddingY is omitted, both paddingX and paddingY will be set to paddingX.
*
* @param {number} [paddingX=0] - The horizontal padding amount.
* @param {number} [paddingY=0] - The vertical padding amount.
* @return {PIXI.Rectangle} Returns itself.
*/
Rectangle.prototype.pad = function (paddingX, paddingY) {
if (paddingX === void 0) { paddingX = 0; }
if (paddingY === void 0) { paddingY = paddingX; }
this.x -= paddingX;
this.y -= paddingY;
this.width += paddingX * 2;
this.height += paddingY * 2;
return this;
};
/**
* Fits this rectangle around the passed one.
*
* @param {PIXI.Rectangle} rectangle - The rectangle to fit.
* @return {PIXI.Rectangle} Returns itself.
*/
Rectangle.prototype.fit = function (rectangle) {
var x1 = Math.max(this.x, rectangle.x);
var x2 = Math.min(this.x + this.width, rectangle.x + rectangle.width);
var y1 = Math.max(this.y, rectangle.y);
var y2 = Math.min(this.y + this.height, rectangle.y + rectangle.height);
this.x = x1;
this.width = Math.max(x2 - x1, 0);
this.y = y1;
this.height = Math.max(y2 - y1, 0);
return this;
};
/**
* Enlarges rectangle that way its corners lie on grid
*
* @param {number} [resolution=1] resolution
* @param {number} [eps=0.001] precision
* @return {PIXI.Rectangle} Returns itself.
*/
Rectangle.prototype.ceil = function (resolution, eps) {
if (resolution === void 0) { resolution = 1; }
if (eps === void 0) { eps = 0.001; }
var x2 = Math.ceil((this.x + this.width - eps) * resolution) / resolution;
var y2 = Math.ceil((this.y + this.height - eps) * resolution) / resolution;
this.x = Math.floor((this.x + eps) * resolution) / resolution;
this.y = Math.floor((this.y + eps) * resolution) / resolution;
this.width = x2 - this.x;
this.height = y2 - this.y;
return this;
};
/**
* Enlarges this rectangle to include the passed rectangle.
*
* @param {PIXI.Rectangle} rectangle - The rectangle to include.
* @return {PIXI.Rectangle} Returns itself.
*/
Rectangle.prototype.enlarge = function (rectangle) {
var x1 = Math.min(this.x, rectangle.x);
var x2 = Math.max(this.x + this.width, rectangle.x + rectangle.width);
var y1 = Math.min(this.y, rectangle.y);
var y2 = Math.max(this.y + this.height, rectangle.y + rectangle.height);
this.x = x1;
this.width = x2 - x1;
this.y = y1;
this.height = y2 - y1;
return this;
};
return Rectangle;
}());
/**
* Common interface for points. Both Point and ObservablePoint implement it
* @memberof PIXI
* @interface IPoint
*/
/**
* X coord
* @memberof PIXI.IPoint#
* @member {number} x
*/
/**
* Y coord
* @memberof PIXI.IPoint#
* @member {number} y
*/
/**
* Sets the point to a new x and y position.
* If y is omitted, both x and y will be set to x.
*
* @method set
* @memberof PIXI.IPoint#
* @param {number} [x=0] - position of the point on the x axis
* @param {number} [y=x] - position of the point on the y axis
*/
/**
* Copies x and y from the given point
* @method copyFrom
* @memberof PIXI.IPoint#
* @param {PIXI.IPoint} p - The point to copy from
* @returns {this} Returns itself.
*/
/**
* Copies x and y into the given point
* @method copyTo
* @memberof PIXI.IPoint#
* @param {PIXI.IPoint} p - The point to copy.
* @returns {PIXI.IPoint} Given point with values updated
*/
/**
* Returns true if the given point is equal to this point
*
* @method equals
* @memberof PIXI.IPoint#
* @param {PIXI.IPoint} p - The point to check
* @returns {boolean} Whether the given point equal to this point
*/
/**
* The Point object represents a location in a two-dimensional coordinate system, where x represents
* the horizontal axis and y represents the vertical axis.
*
* @class
* @memberof PIXI
* @implements IPoint
*/
var Point$1 = /** @class */ (function () {
/**
* @param {number} [x=0] - position of the point on the x axis
* @param {number} [y=0] - position of the point on the y axis
*/
function Point(x, y) {
if (x === void 0) { x = 0; }
if (y === void 0) { y = 0; }
/**
* @member {number}
* @default 0
*/
this.x = x;
/**
* @member {number}
* @default 0
*/
this.y = y;
}
/**
* Creates a clone of this point
*
* @return {PIXI.Point} a copy of the point
*/
Point.prototype.clone = function () {
return new Point(this.x, this.y);
};
/**
* Copies x and y from the given point
*
* @param {PIXI.IPoint} p - The point to copy from
* @returns {this} Returns itself.
*/
Point.prototype.copyFrom = function (p) {
this.set(p.x, p.y);
return this;
};
/**
* Copies x and y into the given point
*
* @param {PIXI.IPoint} p - The point to copy.
* @returns {PIXI.IPoint} Given point with values updated
*/
Point.prototype.copyTo = function (p) {
p.set(this.x, this.y);
return p;
};
/**
* Returns true if the given point is equal to this point
*
* @param {PIXI.IPoint} p - The point to check
* @returns {boolean} Whether the given point equal to this point
*/
Point.prototype.equals = function (p) {
return (p.x === this.x) && (p.y === this.y);
};
/**
* Sets the point to a new x and y position.
* If y is omitted, both x and y will be set to x.
*
* @param {number} [x=0] - position of the point on the x axis
* @param {number} [y=x] - position of the point on the y axis
* @returns {this} Returns itself.
*/
Point.prototype.set = function (x, y) {
if (x === void 0) { x = 0; }
if (y === void 0) { y = x; }
this.x = x;
this.y = y;
return this;
};
return Point;
}());
/**
* The Point object represents a location in a two-dimensional coordinate system, where x represents
* the horizontal axis and y represents the vertical axis.
*
* An ObservablePoint is a point that triggers a callback when the point's position is changed.
*
* @class
* @memberof PIXI
* @implements IPoint
*/
var ObservablePoint$1 = /** @class */ (function () {
/**
* @param {Function} cb - callback when changed
* @param {object} scope - owner of callback
* @param {number} [x=0] - position of the point on the x axis
* @param {number} [y=0] - position of the point on the y axis
*/
function ObservablePoint(cb, scope, x, y) {
if (x === void 0) { x = 0; }
if (y === void 0) { y = 0; }
this._x = x;
this._y = y;
this.cb = cb;
this.scope = scope;
}
/**
* Creates a clone of this point.
* The callback and scope params can be overidden otherwise they will default
* to the clone object's values.
*
* @override
* @param {Function} [cb=null] - callback when changed
* @param {object} [scope=null] - owner of callback
* @return {PIXI.ObservablePoint} a copy of the point
*/
ObservablePoint.prototype.clone = function (cb, scope) {
if (cb === void 0) { cb = this.cb; }
if (scope === void 0) { scope = this.scope; }
return new ObservablePoint(cb, scope, this._x, this._y);
};
/**
* Sets the point to a new x and y position.
* If y is omitted, both x and y will be set to x.
*
* @param {number} [x=0] - position of the point on the x axis
* @param {number} [y=x] - position of the point on the y axis
* @returns {this} Returns itself.
*/
ObservablePoint.prototype.set = function (x, y) {
if (x === void 0) { x = 0; }
if (y === void 0) { y = x; }
if (this._x !== x || this._y !== y) {
this._x = x;
this._y = y;
this.cb.call(this.scope);
}
return this;
};
/**
* Copies x and y from the given point
*
* @param {PIXI.IPoint} p - The point to copy from.
* @returns {this} Returns itself.
*/
ObservablePoint.prototype.copyFrom = function (p) {
if (this._x !== p.x || this._y !== p.y) {
this._x = p.x;
this._y = p.y;
this.cb.call(this.scope);
}
return this;
};
/**
* Copies x and y into the given point
*
* @param {PIXI.IPoint} p - The point to copy.
* @returns {PIXI.IPoint} Given point with values updated
*/
ObservablePoint.prototype.copyTo = function (p) {
p.set(this._x, this._y);
return p;
};
/**
* Returns true if the given point is equal to this point
*
* @param {PIXI.IPoint} p - The point to check
* @returns {boolean} Whether the given point equal to this point
*/
ObservablePoint.prototype.equals = function (p) {
return (p.x === this._x) && (p.y === this._y);
};
Object.defineProperty(ObservablePoint.prototype, "x", {
/**
* The position of the displayObject on the x axis relative to the local coordinates of the parent.
*
* @member {number}
*/
get: function () {
return this._x;
},
set: function (value) {
if (this._x !== value) {
this._x = value;
this.cb.call(this.scope);
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(ObservablePoint.prototype, "y", {
/**
* The position of the displayObject on the x axis relative to the local coordinates of the parent.
*
* @member {number}
*/
get: function () {
return this._y;
},
set: function (value) {
if (this._y !== value) {
this._y = value;
this.cb.call(this.scope);
}
},
enumerable: true,
configurable: true
});
return ObservablePoint;
}());
/**
* The PixiJS Matrix as a class makes it a lot faster.
*
* Here is a representation of it:
* ```js
* | a | c | tx|
* | b | d | ty|
* | 0 | 0 | 1 |
* ```
* @class
* @memberof PIXI
*/
var Matrix$1 = /** @class */ (function () {
/**
* @param {number} [a=1] - x scale
* @param {number} [b=0] - x skew
* @param {number} [c=0] - y skew
* @param {number} [d=1] - y scale
* @param {number} [tx=0] - x translation
* @param {number} [ty=0] - y translation
*/
function Matrix(a, b, c, d, tx, ty) {
if (a === void 0) { a = 1; }
if (b === void 0) { b = 0; }
if (c === void 0) { c = 0; }
if (d === void 0) { d = 1; }
if (tx === void 0) { tx = 0; }
if (ty === void 0) { ty = 0; }
this.array = null;
/**
* @member {number}
* @default 1
*/
this.a = a;
/**
* @member {number}
* @default 0
*/
this.b = b;
/**
* @member {number}
* @default 0
*/
this.c = c;
/**
* @member {number}
* @default 1
*/
this.d = d;
/**
* @member {number}
* @default 0
*/
this.tx = tx;
/**
* @member {number}
* @default 0
*/
this.ty = ty;
}
/**
* Creates a Matrix object based on the given array. The Element to Matrix mapping order is as follows:
*
* a = array[0]
* b = array[1]
* c = array[3]
* d = array[4]
* tx = array[2]
* ty = array[5]
*
* @param {number[]} array - The array that the matrix will be populated from.
*/
Matrix.prototype.fromArray = function (array) {
this.a = array[0];
this.b = array[1];
this.c = array[3];
this.d = array[4];
this.tx = array[2];
this.ty = array[5];
};
/**
* sets the matrix properties
*
* @param {number} a - Matrix component
* @param {number} b - Matrix component
* @param {number} c - Matrix component
* @param {number} d - Matrix component
* @param {number} tx - Matrix component
* @param {number} ty - Matrix component
*
* @return {PIXI.Matrix} This matrix. Good for chaining method calls.
*/
Matrix.prototype.set = function (a, b, c, d, tx, ty) {
this.a = a;
this.b = b;
this.c = c;
this.d = d;
this.tx = tx;
this.ty = ty;
return this;
};
/**
* Creates an array from the current Matrix object.
*
* @param {boolean} transpose - Whether we need to transpose the matrix or not
* @param {Float32Array} [out=new Float32Array(9)] - If provided the array will be assigned to out
* @return {number[]} the newly created array which contains the matrix
*/
Matrix.prototype.toArray = function (transpose, out) {
if (!this.array) {
this.array = new Float32Array(9);
}
var array = out || this.array;
if (transpose) {
array[0] = this.a;
array[1] = this.b;
array[2] = 0;
array[3] = this.c;
array[4] = this.d;
array[5] = 0;
array[6] = this.tx;
array[7] = this.ty;
array[8] = 1;
}
else {
array[0] = this.a;
array[1] = this.c;
array[2] = this.tx;
array[3] = this.b;
array[4] = this.d;
array[5] = this.ty;
array[6] = 0;
array[7] = 0;
array[8] = 1;
}
return array;
};
/**
* Get a new position with the current transformation applied.
* Can be used to go from a child's coordinate space to the world coordinate space. (e.g. rendering)
*
* @param {PIXI.Point} pos - The origin
* @param {PIXI.Point} [newPos] - The point that the new position is assigned to (allowed to be same as input)
* @return {PIXI.Point} The new point, transformed through this matrix
*/
Matrix.prototype.apply = function (pos, newPos) {
newPos = newPos || new Point$1();
var x = pos.x;
var y = pos.y;
newPos.x = (this.a * x) + (this.c * y) + this.tx;
newPos.y = (this.b * x) + (this.d * y) + this.ty;
return newPos;
};
/**
* Get a new position with the inverse of the current transformation applied.
* Can be used to go from the world coordinate space to a child's coordinate space. (e.g. input)
*
* @param {PIXI.Point} pos - The origin
* @param {PIXI.Point} [newPos] - The point that the new position is assigned to (allowed to be same as input)
* @return {PIXI.Point} The new point, inverse-transformed through this matrix
*/
Matrix.prototype.applyInverse = function (pos, newPos) {
newPos = newPos || new Point$1();
var id = 1 / ((this.a * this.d) + (this.c * -this.b));
var x = pos.x;
var y = pos.y;
newPos.x = (this.d * id * x) + (-this.c * id * y) + (((this.ty * this.c) - (this.tx * this.d)) * id);
newPos.y = (this.a * id * y) + (-this.b * id * x) + (((-this.ty * this.a) + (this.tx * this.b)) * id);
return newPos;
};
/**
* Translates the matrix on the x and y.
*
* @param {number} x How much to translate x by
* @param {number} y How much to translate y by
* @return {PIXI.Matrix} This matrix. Good for chaining method calls.
*/
Matrix.prototype.translate = function (x, y) {
this.tx += x;
this.ty += y;
return this;
};
/**
* Applies a scale transformation to the matrix.
*
* @param {number} x The amount to scale horizontally
* @param {number} y The amount to scale vertically
* @return {PIXI.Matrix} This matrix. Good for chaining method calls.
*/
Matrix.prototype.scale = function (x, y) {
this.a *= x;
this.d *= y;
this.c *= x;
this.b *= y;
this.tx *= x;
this.ty *= y;
return this;
};
/**
* Applies a rotation transformation to the matrix.
*
* @param {number} angle - The angle in radians.
* @return {PIXI.Matrix} This matrix. Good for chaining method calls.
*/
Matrix.prototype.rotate = function (angle) {
var cos = Math.cos(angle);
var sin = Math.sin(angle);
var a1 = this.a;
var c1 = this.c;
var tx1 = this.tx;
this.a = (a1 * cos) - (this.b * sin);
this.b = (a1 * sin) + (this.b * cos);
this.c = (c1 * cos) - (this.d * sin);
this.d = (c1 * sin) + (this.d * cos);
this.tx = (tx1 * cos) - (this.ty * sin);
this.ty = (tx1 * sin) + (this.ty * cos);
return this;
};
/**
* Appends the given Matrix to this Matrix.
*
* @param {PIXI.Matrix} matrix - The matrix to append.
* @return {PIXI.Matrix} This matrix. Good for chaining method calls.
*/
Matrix.prototype.append = function (matrix) {
var a1 = this.a;
var b1 = this.b;
var c1 = this.c;
var d1 = this.d;
this.a = (matrix.a * a1) + (matrix.b * c1);
this.b = (matrix.a * b1) + (matrix.b * d1);
this.c = (matrix.c * a1) + (matrix.d * c1);
this.d = (matrix.c * b1) + (matrix.d * d1);
this.tx = (matrix.tx * a1) + (matrix.ty * c1) + this.tx;
this.ty = (matrix.tx * b1) + (matrix.ty * d1) + this.ty;
return this;
};
/**
* Sets the matrix based on all the available properties
*
* @param {number} x - Position on the x axis
* @param {number} y - Position on the y axis
* @param {number} pivotX - Pivot on the x axis
* @param {number} pivotY - Pivot on the y axis
* @param {number} scaleX - Scale on the x axis
* @param {number} scaleY - Scale on the y axis
* @param {number} rotation - Rotation in radians
* @param {number} skewX - Skew on the x axis
* @param {number} skewY - Skew on the y axis
* @return {PIXI.Matrix} This matrix. Good for chaining method calls.
*/
Matrix.prototype.setTransform = function (x, y, pivotX, pivotY, scaleX, scaleY, rotation, skewX, skewY) {
this.a = Math.cos(rotation + skewY) * scaleX;
this.b = Math.sin(rotation + skewY) * scaleX;
this.c = -Math.sin(rotation - skewX) * scaleY;
this.d = Math.cos(rotation - skewX) * scaleY;
this.tx = x - ((pivotX * this.a) + (pivotY * this.c));
this.ty = y - ((pivotX * this.b) + (pivotY * this.d));
return this;
};
/**
* Prepends the given Matrix to this Matrix.
*
* @param {PIXI.Matrix} matrix - The matrix to prepend
* @return {PIXI.Matrix} This matrix. Good for chaining method calls.
*/
Matrix.prototype.prepend = function (matrix) {
var tx1 = this.tx;
if (matrix.a !== 1 || matrix.b !== 0 || matrix.c !== 0 || matrix.d !== 1) {
var a1 = this.a;
var c1 = this.c;
this.a = (a1 * matrix.a) + (this.b * matrix.c);
this.b = (a1 * matrix.b) + (this.b * matrix.d);
this.c = (c1 * matrix.a) + (this.d * matrix.c);
this.d = (c1 * matrix.b) + (this.d * matrix.d);
}
this.tx = (tx1 * matrix.a) + (this.ty * matrix.c) + matrix.tx;
this.ty = (tx1 * matrix.b) + (this.ty * matrix.d) + matrix.ty;
return this;
};
/**
* Decomposes the matrix (x, y, scaleX, scaleY, and rotation) and sets the properties on to a transform.
*
* @param {PIXI.Transform} transform - The transform to apply the properties to.
* @return {PIXI.Transform} The transform with the newly applied properties
*/
Matrix.prototype.decompose = function (transform) {
// sort out rotation / skew..
var a = this.a;
var b = this.b;
var c = this.c;
var d = this.d;
var skewX = -Math.atan2(-c, d);
var skewY = Math.atan2(b, a);
var delta = Math.abs(skewX + skewY);
if (delta < 0.00001 || Math.abs(PI_2$1 - delta) < 0.00001) {
transform.rotation = skewY;
transform.skew.x = transform.skew.y = 0;
}
else {
transform.rotation = 0;
transform.skew.x = skewX;
transform.skew.y = skewY;
}
// next set scale
transform.scale.x = Math.sqrt((a * a) + (b * b));
transform.scale.y = Math.sqrt((c * c) + (d * d));
// next set position
transform.position.x = this.tx;
transform.position.y = this.ty;
return transform;
};
/**
* Inverts this matrix
*
* @return {PIXI.Matrix} This matrix. Good for chaining method calls.
*/
Matrix.prototype.invert = function () {
var a1 = this.a;
var b1 = this.b;
var c1 = this.c;
var d1 = this.d;
var tx1 = this.tx;
var n = (a1 * d1) - (b1 * c1);
this.a = d1 / n;
this.b = -b1 / n;
this.c = -c1 / n;
this.d = a1 / n;
this.tx = ((c1 * this.ty) - (d1 * tx1)) / n;
this.ty = -((a1 * this.ty) - (b1 * tx1)) / n;
return this;
};
/**
* Resets this Matrix to an identity (default) matrix.
*
* @return {PIXI.Matrix} This matrix. Good for chaining method calls.
*/
Matrix.prototype.identity = function () {
this.a = 1;
this.b = 0;
this.c = 0;
this.d = 1;
this.tx = 0;
this.ty = 0;
return this;
};
/**
* Creates a new Matrix object with the same values as this one.
*
* @return {PIXI.Matrix} A copy of this matrix. Good for chaining method calls.
*/
Matrix.prototype.clone = function () {
var matrix = new Matrix();
matrix.a = this.a;
matrix.b = this.b;
matrix.c = this.c;
matrix.d = this.d;
matrix.tx = this.tx;
matrix.ty = this.ty;
return matrix;
};
/**
* Changes the values of the given matrix to be the same as the ones in this matrix
*
* @param {PIXI.Matrix} matrix - The matrix to copy to.
* @return {PIXI.Matrix} The matrix given in parameter with its values updated.
*/
Matrix.prototype.copyTo = function (matrix) {
matrix.a = this.a;
matrix.b = this.b;
matrix.c = this.c;
matrix.d = this.d;
matrix.tx = this.tx;
matrix.ty = this.ty;
return matrix;
};
/**
* Changes the values of the matrix to be the same as the ones in given matrix
*
* @param {PIXI.Matrix} matrix - The matrix to copy from.
* @return {PIXI.Matrix} this
*/
Matrix.prototype.copyFrom = function (matrix) {
this.a = matrix.a;
this.b = matrix.b;
this.c = matrix.c;
this.d = matrix.d;
this.tx = matrix.tx;
this.ty = matrix.ty;
return this;
};
Object.defineProperty(Matrix, "IDENTITY", {
/**
* A default (identity) matrix
*
* @static
* @const
* @member {PIXI.Matrix}
*/
get: function () {
return new Matrix();
},
enumerable: true,
configurable: true
});
Object.defineProperty(Matrix, "TEMP_MATRIX", {
/**
* A temp matrix
*
* @static
* @const
* @member {PIXI.Matrix}
*/
get: function () {
return new Matrix();
},
enumerable: true,
configurable: true
});
return Matrix;
}());
// Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group
/*
* Transform matrix for operation n is:
* | ux | vx |
* | uy | vy |
*/
var ux$1 = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1];
var uy$1 = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1];
var vx$1 = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1];
var vy$1 = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1];
/*
* Alias for {@code Math.sign}.
*/
var signum$1 = Math.sign;
/*
* Initializes `rotationCayley` and `rotationMatrices`. It is called
* only once below.
*/
function init$1() {
for (var i = 0; i < 16; i++) {
var row = [];
for (var j = 0; j < 16; j++) {
/* Multiplies rotation matrices i and j. */
var _ux = signum$1((ux$1[i] * ux$1[j]) + (vx$1[i] * uy$1[j]));
var _uy = signum$1((uy$1[i] * ux$1[j]) + (vy$1[i] * uy$1[j]));
var _vx = signum$1((ux$1[i] * vx$1[j]) + (vx$1[i] * vy$1[j]));
var _vy = signum$1((uy$1[i] * vx$1[j]) + (vy$1[i] * vy$1[j]));
/* Finds rotation matrix matching the product and pushes it. */
for (var k = 0; k < 16; k++) {
if (ux$1[k] === _ux && uy$1[k] === _uy
&& vx$1[k] === _vx && vy$1[k] === _vy) {
row.push(k);
break;
}
}
}
}
for (var i = 0; i < 16; i++) {
var mat = new Matrix$1();
mat.set(ux$1[i], uy$1[i], vx$1[i], vy$1[i], 0, 0);
}
}
init$1();
/**
* Transform that takes care about its versions
*
* @class
* @memberof PIXI
*/
var Transform$1 = /** @class */ (function () {
function Transform() {
/**
* The world transformation matrix.
*
* @member {PIXI.Matrix}
*/
this.worldTransform = new Matrix$1();
/**
* The local transformation matrix.
*
* @member {PIXI.Matrix}
*/
this.localTransform = new Matrix$1();
/**
* The coordinate of the object relative to the local coordinates of the parent.
*
* @member {PIXI.ObservablePoint}
*/
this.position = new ObservablePoint$1(this.onChange, this, 0, 0);
/**
* The scale factor of the object.
*
* @member {PIXI.ObservablePoint}
*/
this.scale = new ObservablePoint$1(this.onChange, this, 1, 1);
/**
* The pivot point of the displayObject that it rotates around.
*
* @member {PIXI.ObservablePoint}
*/
this.pivot = new ObservablePoint$1(this.onChange, this, 0, 0);
/**
* The skew amount, on the x and y axis.
*
* @member {PIXI.ObservablePoint}
*/
this.skew = new ObservablePoint$1(this.updateSkew, this, 0, 0);
/**
* The rotation amount.
*
* @protected
* @member {number}
*/
this._rotation = 0;
/**
* The X-coordinate value of the normalized local X axis,
* the first column of the local transformation matrix without a scale.
*
* @protected
* @member {number}
*/
this._cx = 1;
/**
* The Y-coordinate value of the normalized local X axis,
* the first column of the local transformation matrix without a scale.
*
* @protected
* @member {number}
*/
this._sx = 0;
/**
* The X-coordinate value of the normalized local Y axis,
* the second column of the local transformation matrix without a scale.
*
* @protected
* @member {number}
*/
this._cy = 0;
/**
* The Y-coordinate value of the normalized local Y axis,
* the second column of the local transformation matrix without a scale.
*
* @protected
* @member {number}
*/
this._sy = 1;
/**
* The locally unique ID of the local transform.
*
* @protected
* @member {number}
*/
this._localID = 0;
/**
* The locally unique ID of the local transform
* used to calculate the current local transformation matrix.
*
* @protected
* @member {number}
*/
this._currentLocalID = 0;
/**
* The locally unique ID of the world transform.
*
* @protected
* @member {number}
*/
this._worldID = 0;
/**
* The locally unique ID of the parent's world transform
* used to calculate the current world transformation matrix.
*
* @protected
* @member {number}
*/
this._parentID = 0;
}
/**
* Called when a value changes.
*
* @protected
*/
Transform.prototype.onChange = function () {
this._localID++;
};
/**
* Called when the skew or the rotation changes.
*
* @protected
*/
Transform.prototype.updateSkew = function () {
this._cx = Math.cos(this._rotation + this.skew.y);
this._sx = Math.sin(this._rotation + this.skew.y);
this._cy = -Math.sin(this._rotation - this.skew.x); // cos, added PI/2
this._sy = Math.cos(this._rotation - this.skew.x); // sin, added PI/2
this._localID++;
};
/**
* Updates the local transformation matrix.
*/
Transform.prototype.updateLocalTransform = function () {
var lt = this.localTransform;
if (this._localID !== this._currentLocalID) {
// get the matrix values of the displayobject based on its transform properties..
lt.a = this._cx * this.scale.x;
lt.b = this._sx * this.scale.x;
lt.c = this._cy * this.scale.y;
lt.d = this._sy * this.scale.y;
lt.tx = this.position.x - ((this.pivot.x * lt.a) + (this.pivot.y * lt.c));
lt.ty = this.position.y - ((this.pivot.x * lt.b) + (this.pivot.y * lt.d));
this._currentLocalID = this._localID;
// force an update..
this._parentID = -1;
}
};
/**
* Updates the local and the world transformation matrices.
*
* @param {PIXI.Transform} parentTransform - The parent transform
*/
Transform.prototype.updateTransform = function (parentTransform) {
var lt = this.localTransform;
if (this._localID !== this._currentLocalID) {
// get the matrix values of the displayobject based on its transform properties..
lt.a = this._cx * this.scale.x;
lt.b = this._sx * this.scale.x;
lt.c = this._cy * this.scale.y;
lt.d = this._sy * this.scale.y;
lt.tx = this.position.x - ((this.pivot.x * lt.a) + (this.pivot.y * lt.c));
lt.ty = this.position.y - ((this.pivot.x * lt.b) + (this.pivot.y * lt.d));
this._currentLocalID = this._localID;
// force an update..
this._parentID = -1;
}
if (this._parentID !== parentTransform._worldID) {
// concat the parent matrix with the objects transform.
var pt = parentTransform.worldTransform;
var wt = this.worldTransform;
wt.a = (lt.a * pt.a) + (lt.b * pt.c);
wt.b = (lt.a * pt.b) + (lt.b * pt.d);
wt.c = (lt.c * pt.a) + (lt.d * pt.c);
wt.d = (lt.c * pt.b) + (lt.d * pt.d);
wt.tx = (lt.tx * pt.a) + (lt.ty * pt.c) + pt.tx;
wt.ty = (lt.tx * pt.b) + (lt.ty * pt.d) + pt.ty;
this._parentID = parentTransform._worldID;
// update the id of the transform..
this._worldID++;
}
};
/**
* Decomposes a matrix and sets the transforms properties based on it.
*
* @param {PIXI.Matrix} matrix - The matrix to decompose
*/
Transform.prototype.setFromMatrix = function (matrix) {
matrix.decompose(this);
this._localID++;
};
Object.defineProperty(Transform.prototype, "rotation", {
/**
* The rotation of the object in radians.
*
* @member {number}
*/
get: function () {
return this._rotation;
},
set: function (value) {
if (this._rotation !== value) {
this._rotation = value;
this.updateSkew();
}
},
enumerable: true,
configurable: true
});
/**
* A default (identity) transform
*
* @static
* @constant
* @member {PIXI.Transform}
*/
Transform.IDENTITY = new Transform();
return Transform;
}());
/**
* Math classes and utilities mixed into PIXI namespace.
*
* @lends PIXI
*/
var fragment$5 = "varying vec2 vFilterCoord;\nvarying vec2 vTextureCoord;\n\nuniform vec2 scale;\nuniform mat2 rotation;\nuniform sampler2D uSampler;\nuniform sampler2D mapSampler;\n\nuniform highp vec4 inputSize;\nuniform vec4 inputClamp;\n\nvoid main(void)\n{\n vec4 map = texture2D(mapSampler, vFilterCoord);\n\n map -= 0.5;\n map.xy = scale * inputSize.zw * (rotation * map.xy);\n\n gl_FragColor = texture2D(uSampler, clamp(vec2(vTextureCoord.x + map.x, vTextureCoord.y + map.y), inputClamp.xy, inputClamp.zw));\n}\n";
var vertex$3 = "attribute vec2 aVertexPosition;\n\nuniform mat3 projectionMatrix;\nuniform mat3 filterMatrix;\n\nvarying vec2 vTextureCoord;\nvarying vec2 vFilterCoord;\n\nuniform vec4 inputSize;\nuniform vec4 outputFrame;\n\nvec4 filterVertexPosition( void )\n{\n vec2 position = aVertexPosition * max(outputFrame.zw, vec2(0.)) + outputFrame.xy;\n\n return vec4((projectionMatrix * vec3(position, 1.0)).xy, 0.0, 1.0);\n}\n\nvec2 filterTextureCoord( void )\n{\n return aVertexPosition * (outputFrame.zw * inputSize.zw);\n}\n\nvoid main(void)\n{\n\tgl_Position = filterVertexPosition();\n\tvTextureCoord = filterTextureCoord();\n\tvFilterCoord = ( filterMatrix * vec3( vTextureCoord, 1.0) ).xy;\n}\n";
/**
* The DisplacementFilter class uses the pixel values from the specified texture
* (called the displacement map) to perform a displacement of an object.
*
* You can use this filter to apply all manor of crazy warping effects.
* Currently the `r` property of the texture is used to offset the `x`
* and the `g` property of the texture is used to offset the `y`.
*
* The way it works is it uses the values of the displacement map to look up the
* correct pixels to output. This means it's not technically moving the original.
* Instead, it's starting at the output and asking "which pixel from the original goes here".
* For example, if a displacement map pixel has `red = 1` and the filter scale is `20`,
* this filter will output the pixel approximately 20 pixels to the right of the original.
*
* @class
* @extends PIXI.Filter
* @memberof PIXI.filters
*/
var DisplacementFilter = /** @class */ (function (_super) {
__extends$7(DisplacementFilter, _super);
/**
* @param {PIXI.Sprite} sprite - The sprite used for the displacement map. (make sure its added to the scene!)
* @param {number} [scale] - The scale of the displacement
*/
function DisplacementFilter(sprite, scale) {
var _this = this;
var maskMatrix = new Matrix$1();
sprite.renderable = false;
_this = _super.call(this, vertex$3, fragment$5, {
mapSampler: sprite._texture,
filterMatrix: maskMatrix,
scale: { x: 1, y: 1 },
rotation: new Float32Array([1, 0, 0, 1]),
}) || this;
_this.maskSprite = sprite;
_this.maskMatrix = maskMatrix;
if (scale === null || scale === undefined) {
scale = 20;
}
/**
* scaleX, scaleY for displacements
* @member {PIXI.Point}
*/
_this.scale = new Point$1(scale, scale);
return _this;
}
/**
* Applies the filter.
*
* @param {PIXI.systems.FilterSystem} filterManager - The manager.
* @param {PIXI.RenderTexture} input - The input target.
* @param {PIXI.RenderTexture} output - The output target.
* @param {PIXI.CLEAR_MODES} clearMode - clearMode.
*/
DisplacementFilter.prototype.apply = function (filterManager, input, output, clearMode) {
// fill maskMatrix with _normalized sprite texture coords_
this.uniforms.filterMatrix = filterManager.calculateSpriteMatrix(this.maskMatrix, this.maskSprite);
this.uniforms.scale.x = this.scale.x;
this.uniforms.scale.y = this.scale.y;
// Extract rotation from world transform
var wt = this.maskSprite.worldTransform;
var lenX = Math.sqrt((wt.a * wt.a) + (wt.b * wt.b));
var lenY = Math.sqrt((wt.c * wt.c) + (wt.d * wt.d));
if (lenX !== 0 && lenY !== 0) {
this.uniforms.rotation[0] = wt.a / lenX;
this.uniforms.rotation[1] = wt.b / lenX;
this.uniforms.rotation[2] = wt.c / lenY;
this.uniforms.rotation[3] = wt.d / lenY;
}
// draw the filter...
filterManager.applyFilter(this, input, output, clearMode);
};
Object.defineProperty(DisplacementFilter.prototype, "map", {
/**
* The texture used for the displacement map. Must be power of 2 sized texture.
*
* @member {PIXI.Texture}
*/
get: function () {
return this.uniforms.mapSampler;
},
set: function (value) {
this.uniforms.mapSampler = value;
},
enumerable: true,
configurable: true
});
return DisplacementFilter;
}(Filter));
/*!
* @pixi/filter-fxaa - v5.2.1
* Compiled Tue, 04 Feb 2020 21:48:29 UTC
*
* @pixi/filter-fxaa is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
*/
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics$8 = function(d, b) {
extendStatics$8 = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
return extendStatics$8(d, b);
};
function __extends$8(d, b) {
extendStatics$8(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var vertex$4 = "\nattribute vec2 aVertexPosition;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 v_rgbNW;\nvarying vec2 v_rgbNE;\nvarying vec2 v_rgbSW;\nvarying vec2 v_rgbSE;\nvarying vec2 v_rgbM;\n\nvarying vec2 vFragCoord;\n\nuniform vec4 inputPixel;\nuniform vec4 outputFrame;\n\nvec4 filterVertexPosition( void )\n{\n vec2 position = aVertexPosition * max(outputFrame.zw, vec2(0.)) + outputFrame.xy;\n\n return vec4((projectionMatrix * vec3(position, 1.0)).xy, 0.0, 1.0);\n}\n\nvoid texcoords(vec2 fragCoord, vec2 inverseVP,\n out vec2 v_rgbNW, out vec2 v_rgbNE,\n out vec2 v_rgbSW, out vec2 v_rgbSE,\n out vec2 v_rgbM) {\n v_rgbNW = (fragCoord + vec2(-1.0, -1.0)) * inverseVP;\n v_rgbNE = (fragCoord + vec2(1.0, -1.0)) * inverseVP;\n v_rgbSW = (fragCoord + vec2(-1.0, 1.0)) * inverseVP;\n v_rgbSE = (fragCoord + vec2(1.0, 1.0)) * inverseVP;\n v_rgbM = vec2(fragCoord * inverseVP);\n}\n\nvoid main(void) {\n\n gl_Position = filterVertexPosition();\n\n vFragCoord = aVertexPosition * outputFrame.zw;\n\n texcoords(vFragCoord, inputPixel.zw, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM);\n}\n";
var fragment$6 = "varying vec2 v_rgbNW;\nvarying vec2 v_rgbNE;\nvarying vec2 v_rgbSW;\nvarying vec2 v_rgbSE;\nvarying vec2 v_rgbM;\n\nvarying vec2 vFragCoord;\nuniform sampler2D uSampler;\nuniform highp vec4 inputPixel;\n\n\n/**\n Basic FXAA implementation based on the code on geeks3d.com with the\n modification that the texture2DLod stuff was removed since it's\n unsupported by WebGL.\n\n --\n\n From:\n https://github.com/mitsuhiko/webgl-meincraft\n\n Copyright (c) 2011 by Armin Ronacher.\n\n Some rights reserved.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions are\n met:\n\n * Redistributions of source code must retain the above copyright\n notice, this list of conditions and the following disclaimer.\n\n * Redistributions in binary form must reproduce the above\n copyright notice, this list of conditions and the following\n disclaimer in the documentation and/or other materials provided\n with the distribution.\n\n * The names of the contributors may not be used to endorse or\n promote products derived from this software without specific\n prior written permission.\n\n THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\n#ifndef FXAA_REDUCE_MIN\n#define FXAA_REDUCE_MIN (1.0/ 128.0)\n#endif\n#ifndef FXAA_REDUCE_MUL\n#define FXAA_REDUCE_MUL (1.0 / 8.0)\n#endif\n#ifndef FXAA_SPAN_MAX\n#define FXAA_SPAN_MAX 8.0\n#endif\n\n//optimized version for mobile, where dependent\n//texture reads can be a bottleneck\nvec4 fxaa(sampler2D tex, vec2 fragCoord, vec2 inverseVP,\n vec2 v_rgbNW, vec2 v_rgbNE,\n vec2 v_rgbSW, vec2 v_rgbSE,\n vec2 v_rgbM) {\n vec4 color;\n vec3 rgbNW = texture2D(tex, v_rgbNW).xyz;\n vec3 rgbNE = texture2D(tex, v_rgbNE).xyz;\n vec3 rgbSW = texture2D(tex, v_rgbSW).xyz;\n vec3 rgbSE = texture2D(tex, v_rgbSE).xyz;\n vec4 texColor = texture2D(tex, v_rgbM);\n vec3 rgbM = texColor.xyz;\n vec3 luma = vec3(0.299, 0.587, 0.114);\n float lumaNW = dot(rgbNW, luma);\n float lumaNE = dot(rgbNE, luma);\n float lumaSW = dot(rgbSW, luma);\n float lumaSE = dot(rgbSE, luma);\n float lumaM = dot(rgbM, luma);\n float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));\n\n mediump vec2 dir;\n dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n\n float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) *\n (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);\n\n float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),\n max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),\n dir * rcpDirMin)) * inverseVP;\n\n vec3 rgbA = 0.5 * (\n texture2D(tex, fragCoord * inverseVP + dir * (1.0 / 3.0 - 0.5)).xyz +\n texture2D(tex, fragCoord * inverseVP + dir * (2.0 / 3.0 - 0.5)).xyz);\n vec3 rgbB = rgbA * 0.5 + 0.25 * (\n texture2D(tex, fragCoord * inverseVP + dir * -0.5).xyz +\n texture2D(tex, fragCoord * inverseVP + dir * 0.5).xyz);\n\n float lumaB = dot(rgbB, luma);\n if ((lumaB < lumaMin) || (lumaB > lumaMax))\n color = vec4(rgbA, texColor.a);\n else\n color = vec4(rgbB, texColor.a);\n return color;\n}\n\nvoid main() {\n\n vec4 color;\n\n color = fxaa(uSampler, vFragCoord, inputPixel.zw, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM);\n\n gl_FragColor = color;\n}\n";
/**
* Basic FXAA (Fast Approximate Anti-Aliasing) implementation based on the code on geeks3d.com
* with the modification that the texture2DLod stuff was removed since it is unsupported by WebGL.
*
* @see https://github.com/mitsuhiko/webgl-meincraft
*
* @class
* @extends PIXI.Filter
* @memberof PIXI.filters
*
*/
var FXAAFilter = /** @class */ (function (_super) {
__extends$8(FXAAFilter, _super);
function FXAAFilter() {
// TODO - needs work
return _super.call(this, vertex$4, fragment$6) || this;
}
return FXAAFilter;
}(Filter));
/*!
* @pixi/filter-noise - v5.2.1
* Compiled Tue, 04 Feb 2020 21:48:29 UTC
*
* @pixi/filter-noise is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
*/
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics$9 = function(d, b) {
extendStatics$9 = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
return extendStatics$9(d, b);
};
function __extends$9(d, b) {
extendStatics$9(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var fragment$7 = "precision highp float;\n\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\n\nuniform float uNoise;\nuniform float uSeed;\nuniform sampler2D uSampler;\n\nfloat rand(vec2 co)\n{\n return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453);\n}\n\nvoid main()\n{\n vec4 color = texture2D(uSampler, vTextureCoord);\n float randomValue = rand(gl_FragCoord.xy * uSeed);\n float diff = (randomValue - 0.5) * uNoise;\n\n // Un-premultiply alpha before applying the color matrix. See issue #3539.\n if (color.a > 0.0) {\n color.rgb /= color.a;\n }\n\n color.r += diff;\n color.g += diff;\n color.b += diff;\n\n // Premultiply alpha again.\n color.rgb *= color.a;\n\n gl_FragColor = color;\n}\n";
/**
* @author Vico @vicocotea
* original filter: https://github.com/evanw/glfx.js/blob/master/src/filters/adjust/noise.js
*/
/**
* A Noise effect filter.
*
* @class
* @extends PIXI.Filter
* @memberof PIXI.filters
*/
var NoiseFilter = /** @class */ (function (_super) {
__extends$9(NoiseFilter, _super);
/**
* @param {number} [noise=0.5] - The noise intensity, should be a normalized value in the range [0, 1].
* @param {number} [seed] - A random seed for the noise generation. Default is `Math.random()`.
*/
function NoiseFilter(noise, seed) {
if (noise === void 0) { noise = 0.5; }
if (seed === void 0) { seed = Math.random(); }
var _this = _super.call(this, defaultFilter, fragment$7, {
uNoise: 0,
uSeed: 0,
}) || this;
_this.noise = noise;
_this.seed = seed;
return _this;
}
Object.defineProperty(NoiseFilter.prototype, "noise", {
/**
* The amount of noise to apply, this value should be in the range (0, 1].
*
* @member {number}
* @default 0.5
*/
get: function () {
return this.uniforms.uNoise;
},
set: function (value) {
this.uniforms.uNoise = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(NoiseFilter.prototype, "seed", {
/**
* A seed value to apply to the random noise generation. `Math.random()` is a good value to use.
*
* @member {number}
*/
get: function () {
return this.uniforms.uSeed;
},
set: function (value) {
this.uniforms.uSeed = value;
},
enumerable: true,
configurable: true
});
return NoiseFilter;
}(Filter));
/*!
* @pixi/mixin-cache-as-bitmap - v5.2.1
* Compiled Tue, 04 Feb 2020 21:48:29 UTC
*
* @pixi/mixin-cache-as-bitmap is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
*/
var _tempMatrix = new Matrix();
DisplayObject.prototype._cacheAsBitmap = false;
DisplayObject.prototype._cacheData = false;
// figured theres no point adding ALL the extra variables to prototype.
// this model can hold the information needed. This can also be generated on demand as
// most objects are not cached as bitmaps.
/**
* @class
* @ignore
*/
var CacheData = function CacheData()
{
this.textureCacheId = null;
this.originalRender = null;
this.originalRenderCanvas = null;
this.originalCalculateBounds = null;
this.originalGetLocalBounds = null;
this.originalUpdateTransform = null;
this.originalHitTest = null;
this.originalDestroy = null;
this.originalMask = null;
this.originalFilterArea = null;
this.sprite = null;
};
Object.defineProperties(DisplayObject.prototype, {
/**
* Set this to true if you want this display object to be cached as a bitmap.
* This basically takes a snap shot of the display object as it is at that moment. It can
* provide a performance benefit for complex static displayObjects.
* To remove simply set this property to `false`
*
* IMPORTANT GOTCHA - Make sure that all your textures are preloaded BEFORE setting this property to true
* as it will take a snapshot of what is currently there. If the textures have not loaded then they will not appear.
*
* @member {boolean}
* @memberof PIXI.DisplayObject#
*/
cacheAsBitmap: {
get: function get()
{
return this._cacheAsBitmap;
},
set: function set(value)
{
if (this._cacheAsBitmap === value)
{
return;
}
this._cacheAsBitmap = value;
var data;
if (value)
{
if (!this._cacheData)
{
this._cacheData = new CacheData();
}
data = this._cacheData;
data.originalRender = this.render;
data.originalRenderCanvas = this.renderCanvas;
data.originalUpdateTransform = this.updateTransform;
data.originalCalculateBounds = this.calculateBounds;
data.originalGetLocalBounds = this.getLocalBounds;
data.originalDestroy = this.destroy;
data.originalContainsPoint = this.containsPoint;
data.originalMask = this._mask;
data.originalFilterArea = this.filterArea;
this.render = this._renderCached;
this.renderCanvas = this._renderCachedCanvas;
this.destroy = this._cacheAsBitmapDestroy;
}
else
{
data = this._cacheData;
if (data.sprite)
{
this._destroyCachedDisplayObject();
}
this.render = data.originalRender;
this.renderCanvas = data.originalRenderCanvas;
this.calculateBounds = data.originalCalculateBounds;
this.getLocalBounds = data.originalGetLocalBounds;
this.destroy = data.originalDestroy;
this.updateTransform = data.originalUpdateTransform;
this.containsPoint = data.originalContainsPoint;
this._mask = data.originalMask;
this.filterArea = data.originalFilterArea;
}
},
},
});
/**
* Renders a cached version of the sprite with WebGL
*
* @private
* @function _renderCached
* @memberof PIXI.DisplayObject#
* @param {PIXI.Renderer} renderer - the WebGL renderer
*/
DisplayObject.prototype._renderCached = function _renderCached(renderer)
{
if (!this.visible || this.worldAlpha <= 0 || !this.renderable)
{
return;
}
this._initCachedDisplayObject(renderer);
this._cacheData.sprite.transform._worldID = this.transform._worldID;
this._cacheData.sprite.worldAlpha = this.worldAlpha;
this._cacheData.sprite._render(renderer);
};
/**
* Prepares the WebGL renderer to cache the sprite
*
* @private
* @function _initCachedDisplayObject
* @memberof PIXI.DisplayObject#
* @param {PIXI.Renderer} renderer - the WebGL renderer
*/
DisplayObject.prototype._initCachedDisplayObject = function _initCachedDisplayObject(renderer)
{
if (this._cacheData && this._cacheData.sprite)
{
return;
}
// make sure alpha is set to 1 otherwise it will get rendered as invisible!
var cacheAlpha = this.alpha;
this.alpha = 1;
// first we flush anything left in the renderer (otherwise it would get rendered to the cached texture)
renderer.batch.flush();
// this.filters= [];
// next we find the dimensions of the untransformed object
// this function also calls updatetransform on all its children as part of the measuring.
// This means we don't need to update the transform again in this function
// TODO pass an object to clone too? saves having to create a new one each time!
var bounds = this.getLocalBounds().clone();
// add some padding!
if (this.filters)
{
var padding = this.filters[0].padding;
bounds.pad(padding);
}
bounds.ceil(settings.RESOLUTION);
// for now we cache the current renderTarget that the WebGL renderer is currently using.
// this could be more elegant..
var cachedRenderTexture = renderer.renderTexture.current;
var cachedSourceFrame = renderer.renderTexture.sourceFrame;
var cachedProjectionTransform = renderer.projection.transform;
// We also store the filter stack - I will definitely look to change how this works a little later down the line.
// const stack = renderer.filterManager.filterStack;
// this renderTexture will be used to store the cached DisplayObject
var renderTexture = RenderTexture.create(bounds.width, bounds.height);
var textureCacheId = "cacheAsBitmap_" + (uid());
this._cacheData.textureCacheId = textureCacheId;
BaseTexture.addToCache(renderTexture.baseTexture, textureCacheId);
Texture.addToCache(renderTexture, textureCacheId);
// need to set //
var m = _tempMatrix;
m.tx = -bounds.x;
m.ty = -bounds.y;
// reset
this.transform.worldTransform.identity();
// set all properties to there original so we can render to a texture
this.render = this._cacheData.originalRender;
renderer.render(this, renderTexture, true, m, true);
// now restore the state be setting the new properties
renderer.projection.transform = cachedProjectionTransform;
renderer.renderTexture.bind(cachedRenderTexture, cachedSourceFrame);
// renderer.filterManager.filterStack = stack;
this.render = this._renderCached;
// the rest is the same as for Canvas
this.updateTransform = this.displayObjectUpdateTransform;
this.calculateBounds = this._calculateCachedBounds;
this.getLocalBounds = this._getCachedLocalBounds;
this._mask = null;
this.filterArea = null;
// create our cached sprite
var cachedSprite = new Sprite(renderTexture);
cachedSprite.transform.worldTransform = this.transform.worldTransform;
cachedSprite.anchor.x = -(bounds.x / bounds.width);
cachedSprite.anchor.y = -(bounds.y / bounds.height);
cachedSprite.alpha = cacheAlpha;
cachedSprite._bounds = this._bounds;
this._cacheData.sprite = cachedSprite;
this.transform._parentID = -1;
// restore the transform of the cached sprite to avoid the nasty flicker..
if (!this.parent)
{
this.parent = renderer._tempDisplayObjectParent;
this.updateTransform();
this.parent = null;
}
else
{
this.updateTransform();
}
// map the hit test..
this.containsPoint = cachedSprite.containsPoint.bind(cachedSprite);
};
/**
* Renders a cached version of the sprite with canvas
*
* @private
* @function _renderCachedCanvas
* @memberof PIXI.DisplayObject#
* @param {PIXI.Renderer} renderer - the WebGL renderer
*/
DisplayObject.prototype._renderCachedCanvas = function _renderCachedCanvas(renderer)
{
if (!this.visible || this.worldAlpha <= 0 || !this.renderable)
{
return;
}
this._initCachedDisplayObjectCanvas(renderer);
this._cacheData.sprite.worldAlpha = this.worldAlpha;
this._cacheData.sprite._renderCanvas(renderer);
};
// TODO this can be the same as the WebGL version.. will need to do a little tweaking first though..
/**
* Prepares the Canvas renderer to cache the sprite
*
* @private
* @function _initCachedDisplayObjectCanvas
* @memberof PIXI.DisplayObject#
* @param {PIXI.Renderer} renderer - the WebGL renderer
*/
DisplayObject.prototype._initCachedDisplayObjectCanvas = function _initCachedDisplayObjectCanvas(renderer)
{
if (this._cacheData && this._cacheData.sprite)
{
return;
}
// get bounds actually transforms the object for us already!
var bounds = this.getLocalBounds();
var cacheAlpha = this.alpha;
this.alpha = 1;
var cachedRenderTarget = renderer.context;
bounds.ceil(settings.RESOLUTION);
var renderTexture = RenderTexture.create(bounds.width, bounds.height);
var textureCacheId = "cacheAsBitmap_" + (uid());
this._cacheData.textureCacheId = textureCacheId;
BaseTexture.addToCache(renderTexture.baseTexture, textureCacheId);
Texture.addToCache(renderTexture, textureCacheId);
// need to set //
var m = _tempMatrix;
this.transform.localTransform.copyTo(m);
m.invert();
m.tx -= bounds.x;
m.ty -= bounds.y;
// m.append(this.transform.worldTransform.)
// set all properties to there original so we can render to a texture
this.renderCanvas = this._cacheData.originalRenderCanvas;
// renderTexture.render(this, m, true);
renderer.render(this, renderTexture, true, m, false);
// now restore the state be setting the new properties
renderer.context = cachedRenderTarget;
this.renderCanvas = this._renderCachedCanvas;
// the rest is the same as for WebGL
this.updateTransform = this.displayObjectUpdateTransform;
this.calculateBounds = this._calculateCachedBounds;
this.getLocalBounds = this._getCachedLocalBounds;
this._mask = null;
this.filterArea = null;
// create our cached sprite
var cachedSprite = new Sprite(renderTexture);
cachedSprite.transform.worldTransform = this.transform.worldTransform;
cachedSprite.anchor.x = -(bounds.x / bounds.width);
cachedSprite.anchor.y = -(bounds.y / bounds.height);
cachedSprite.alpha = cacheAlpha;
cachedSprite._bounds = this._bounds;
this._cacheData.sprite = cachedSprite;
this.transform._parentID = -1;
// restore the transform of the cached sprite to avoid the nasty flicker..
if (!this.parent)
{
this.parent = renderer._tempDisplayObjectParent;
this.updateTransform();
this.parent = null;
}
else
{
this.updateTransform();
}
// map the hit test..
this.containsPoint = cachedSprite.containsPoint.bind(cachedSprite);
};
/**
* Calculates the bounds of the cached sprite
*
* @private
*/
DisplayObject.prototype._calculateCachedBounds = function _calculateCachedBounds()
{
this._bounds.clear();
this._cacheData.sprite.transform._worldID = this.transform._worldID;
this._cacheData.sprite._calculateBounds();
this._bounds.updateID = this._boundsID;
};
/**
* Gets the bounds of the cached sprite.
*
* @private
* @return {Rectangle} The local bounds.
*/
DisplayObject.prototype._getCachedLocalBounds = function _getCachedLocalBounds()
{
return this._cacheData.sprite.getLocalBounds();
};
/**
* Destroys the cached sprite.
*
* @private
*/
DisplayObject.prototype._destroyCachedDisplayObject = function _destroyCachedDisplayObject()
{
this._cacheData.sprite._texture.destroy(true);
this._cacheData.sprite = null;
BaseTexture.removeFromCache(this._cacheData.textureCacheId);
Texture.removeFromCache(this._cacheData.textureCacheId);
this._cacheData.textureCacheId = null;
};
/**
* Destroys the cached object.
*
* @private
* @param {object|boolean} [options] - Options parameter. A boolean will act as if all options
* have been set to that value.
* Used when destroying containers, see the Container.destroy method.
*/
DisplayObject.prototype._cacheAsBitmapDestroy = function _cacheAsBitmapDestroy(options)
{
this.cacheAsBitmap = false;
this.destroy(options);
};
/*!
* @pixi/mixin-get-child-by-name - v5.2.1
* Compiled Tue, 04 Feb 2020 21:48:29 UTC
*
* @pixi/mixin-get-child-by-name is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
*/
/**
* The instance name of the object.
*
* @memberof PIXI.DisplayObject#
* @member {string} name
*/
DisplayObject.prototype.name = null;
/**
* Returns the display object in the container.
*
* @method getChildByName
* @memberof PIXI.Container#
* @param {string} name - Instance name.
* @return {PIXI.DisplayObject} The child with the specified name.
*/
Container.prototype.getChildByName = function getChildByName(name)
{
for (var i = 0; i < this.children.length; i++)
{
if (this.children[i].name === name)
{
return this.children[i];
}
}
return null;
};
/*!
* @pixi/mixin-get-global-position - v5.2.1
* Compiled Tue, 04 Feb 2020 21:48:29 UTC
*
* @pixi/mixin-get-global-position is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
*/
/**
* Returns the global position of the displayObject. Does not depend on object scale, rotation and pivot.
*
* @method getGlobalPosition
* @memberof PIXI.DisplayObject#
* @param {PIXI.Point} [point=new PIXI.Point()] - The point to write the global value to.
* @param {boolean} [skipUpdate=false] - Setting to true will stop the transforms of the scene graph from
* being updated. This means the calculation returned MAY be out of date BUT will give you a
* nice performance boost.
* @return {PIXI.Point} The updated point.
*/
DisplayObject.prototype.getGlobalPosition = function getGlobalPosition(point, skipUpdate)
{
if ( point === void 0 ) { point = new Point(); }
if ( skipUpdate === void 0 ) { skipUpdate = false; }
if (this.parent)
{
this.parent.toGlobal(this.position, point, skipUpdate);
}
else
{
point.x = this.position.x;
point.y = this.position.y;
}
return point;
};
/*!
* @pixi/mesh - v5.2.1
* Compiled Tue, 04 Feb 2020 21:48:29 UTC
*
* @pixi/mesh is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
*/
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics$a = function(d, b) {
extendStatics$a = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
return extendStatics$a(d, b);
};
function __extends$a(d, b) {
extendStatics$a(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
/**
* Class controls cache for UV mapping from Texture normal space to BaseTexture normal space.
*
* @class
* @memberof PIXI
*/
var MeshBatchUvs = /** @class */ (function () {
/**
* @param {PIXI.Buffer} uvBuffer - Buffer with normalized uv's
* @param {PIXI.TextureMatrix} uvMatrix - Material UV matrix
*/
function MeshBatchUvs(uvBuffer, uvMatrix) {
/**
* Buffer with normalized UV's
* @member {PIXI.Buffer}
*/
this.uvBuffer = uvBuffer;
/**
* Material UV matrix
* @member {PIXI.TextureMatrix}
*/
this.uvMatrix = uvMatrix;
/**
* UV Buffer data
* @member {Float32Array}
* @readonly
*/
this.data = null;
this._bufferUpdateId = -1;
this._textureUpdateId = -1;
this._updateID = 0;
}
/**
* updates
*
* @param {boolean} [forceUpdate] - force the update
*/
MeshBatchUvs.prototype.update = function (forceUpdate) {
if (!forceUpdate
&& this._bufferUpdateId === this.uvBuffer._updateID
&& this._textureUpdateId === this.uvMatrix._updateID) {
return;
}
this._bufferUpdateId = this.uvBuffer._updateID;
this._textureUpdateId = this.uvMatrix._updateID;
var data = this.uvBuffer.data;
if (!this.data || this.data.length !== data.length) {
this.data = new Float32Array(data.length);
}
this.uvMatrix.multiplyUvs(data, this.data);
this._updateID++;
};
return MeshBatchUvs;
}());
var tempPoint$2 = new Point();
var tempPolygon = new Polygon();
/**
* Base mesh class.
*
* This class empowers you to have maximum flexibility to render any kind of WebGL visuals you can think of.
* This class assumes a certain level of WebGL knowledge.
* If you know a bit this should abstract enough away to make you life easier!
*
* Pretty much ALL WebGL can be broken down into the following:
* - Geometry - The structure and data for the mesh. This can include anything from positions, uvs, normals, colors etc..
* - Shader - This is the shader that PixiJS will render the geometry with (attributes in the shader must match the geometry)
* - State - This is the state of WebGL required to render the mesh.
*
* Through a combination of the above elements you can render anything you want, 2D or 3D!
*
* @class
* @extends PIXI.Container
* @memberof PIXI
*/
var Mesh = /** @class */ (function (_super) {
__extends$a(Mesh, _super);
/* eslint-enable @typescript-eslint/ban-ts-ignore */
/**
* @param {PIXI.Geometry} geometry the geometry the mesh will use
* @param {PIXI.MeshMaterial} shader the shader the mesh will use
* @param {PIXI.State} [state] the state that the WebGL context is required to be in to render the mesh
* if no state is provided, uses {@link PIXI.State.for2d} to create a 2D state for PixiJS.
* @param {number} [drawMode=PIXI.DRAW_MODES.TRIANGLES] the drawMode, can be any of the PIXI.DRAW_MODES consts
*/
function Mesh(geometry, shader, state, drawMode) {
if (drawMode === void 0) { drawMode = exports.DRAW_MODES.TRIANGLES; }
var _this = _super.call(this) || this;
/**
* Includes vertex positions, face indices, normals, colors, UVs, and
* custom attributes within buffers, reducing the cost of passing all
* this data to the GPU. Can be shared between multiple Mesh objects.
* @member {PIXI.Geometry}
* @readonly
*/
_this.geometry = geometry;
geometry.refCount++;
/**
* Represents the vertex and fragment shaders that processes the geometry and runs on the GPU.
* Can be shared between multiple Mesh objects.
* @member {PIXI.Shader|PIXI.MeshMaterial}
*/
_this.shader = shader;
/**
* Represents the WebGL state the Mesh required to render, excludes shader and geometry. E.g.,
* blend mode, culling, depth testing, direction of rendering triangles, backface, etc.
* @member {PIXI.State}
*/
_this.state = state || State.for2d();
/**
* The way the Mesh should be drawn, can be any of the {@link PIXI.DRAW_MODES} constants.
*
* @member {number}
* @see PIXI.DRAW_MODES
*/
_this.drawMode = drawMode;
/**
* Typically the index of the IndexBuffer where to start drawing.
* @member {number}
* @default 0
*/
_this.start = 0;
/**
* How much of the geometry to draw, by default `0` renders everything.
* @member {number}
* @default 0
*/
_this.size = 0;
/**
* thease are used as easy access for batching
* @member {Float32Array}
* @private
*/
_this.uvs = null;
/**
* thease are used as easy access for batching
* @member {Uint16Array}
* @private
*/
_this.indices = null;
/**
* this is the caching layer used by the batcher
* @member {Float32Array}
* @private
*/
_this.vertexData = new Float32Array(1);
/**
* If geometry is changed used to decide to re-transform
* the vertexData.
* @member {number}
* @private
*/
_this.vertexDirty = 0;
_this._transformID = -1;
// Inherited from DisplayMode, set defaults
_this.tint = 0xFFFFFF;
_this.blendMode = exports.BLEND_MODES.NORMAL;
/**
* Internal roundPixels field
*
* @member {boolean}
* @private
*/
_this._roundPixels = settings.ROUND_PIXELS;
/**
* Batched UV's are cached for atlas textures
* @member {PIXI.MeshBatchUvs}
* @private
*/
_this.batchUvs = null;
return _this;
}
Object.defineProperty(Mesh.prototype, "uvBuffer", {
/**
* To change mesh uv's, change its uvBuffer data and increment its _updateID.
* @member {PIXI.Buffer}
* @readonly
*/
get: function () {
return this.geometry.buffers[1];
},
enumerable: true,
configurable: true
});
Object.defineProperty(Mesh.prototype, "verticesBuffer", {
/**
* To change mesh vertices, change its uvBuffer data and increment its _updateID.
* Incrementing _updateID is optional because most of Mesh objects do it anyway.
* @member {PIXI.Buffer}
* @readonly
*/
get: function () {
return this.geometry.buffers[0];
},
enumerable: true,
configurable: true
});
Object.defineProperty(Mesh.prototype, "material", {
get: function () {
return this.shader;
},
/**
* Alias for {@link PIXI.Mesh#shader}.
* @member {PIXI.MeshMaterial}
*/
set: function (value) {
this.shader = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Mesh.prototype, "blendMode", {
get: function () {
return this.state.blendMode;
},
/**
* The blend mode to be applied to the Mesh. Apply a value of
* `PIXI.BLEND_MODES.NORMAL` to reset the blend mode.
*
* @member {number}
* @default PIXI.BLEND_MODES.NORMAL;
* @see PIXI.BLEND_MODES
*/
set: function (value) {
this.state.blendMode = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Mesh.prototype, "roundPixels", {
get: function () {
return this._roundPixels;
},
/**
* If true PixiJS will Math.floor() x/y values when rendering, stopping pixel interpolation.
* Advantages can include sharper image quality (like text) and faster rendering on canvas.
* The main disadvantage is movement of objects may appear less smooth.
* To set the global default, change {@link PIXI.settings.ROUND_PIXELS}
*
* @member {boolean}
* @default false
*/
set: function (value) {
if (this._roundPixels !== value) {
this._transformID = -1;
}
this._roundPixels = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Mesh.prototype, "tint", {
/**
* The multiply tint applied to the Mesh. This is a hex value. A value of
* `0xFFFFFF` will remove any tint effect.
*
* @member {number}
* @default 0xFFFFFF
*/
get: function () {
return this.shader.tint;
},
set: function (value) {
this.shader.tint = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Mesh.prototype, "texture", {
/**
* The texture that the Mesh uses.
*
* @member {PIXI.Texture}
*/
get: function () {
return this.shader.texture;
},
set: function (value) {
this.shader.texture = value;
},
enumerable: true,
configurable: true
});
/**
* Standard renderer draw.
* @protected
* @param {PIXI.Renderer} renderer - Instance to renderer.
*/
Mesh.prototype._render = function (renderer) {
// set properties for batching..
// TODO could use a different way to grab verts?
var vertices = this.geometry.buffers[0].data;
// TODO benchmark check for attribute size..
if (this.shader.batchable
&& this.drawMode === exports.DRAW_MODES.TRIANGLES
&& vertices.length < Mesh.BATCHABLE_SIZE * 2) {
this._renderToBatch(renderer);
}
else {
this._renderDefault(renderer);
}
};
/**
* Standard non-batching way of rendering.
* @protected
* @param {PIXI.Renderer} renderer - Instance to renderer.
*/
Mesh.prototype._renderDefault = function (renderer) {
var shader = this.shader;
shader.alpha = this.worldAlpha;
if (shader.update) {
shader.update();
}
renderer.batch.flush();
if (shader.program.uniformData.translationMatrix) {
shader.uniforms.translationMatrix = this.transform.worldTransform.toArray(true);
}
// bind and sync uniforms..
renderer.shader.bind(shader);
// set state..
renderer.state.set(this.state);
// bind the geometry...
renderer.geometry.bind(this.geometry, shader);
// then render it
renderer.geometry.draw(this.drawMode, this.size, this.start, this.geometry.instanceCount);
};
/**
* Rendering by using the Batch system.
* @protected
* @param {PIXI.Renderer} renderer - Instance to renderer.
*/
Mesh.prototype._renderToBatch = function (renderer) {
var geometry = this.geometry;
if (this.shader.uvMatrix) {
this.shader.uvMatrix.update();
this.calculateUvs();
}
// set properties for batching..
this.calculateVertices();
this.indices = geometry.indexBuffer.data;
this._tintRGB = this.shader._tintRGB;
this._texture = this.shader.texture;
var pluginName = this.material.pluginName;
renderer.batch.setObjectRenderer(renderer.plugins[pluginName]);
renderer.plugins[pluginName].render(this);
};
/**
* Updates vertexData field based on transform and vertices
*/
Mesh.prototype.calculateVertices = function () {
var geometry = this.geometry;
var vertices = geometry.buffers[0].data;
if (geometry.vertexDirtyId === this.vertexDirty && this._transformID === this.transform._worldID) {
return;
}
this._transformID = this.transform._worldID;
if (this.vertexData.length !== vertices.length) {
this.vertexData = new Float32Array(vertices.length);
}
var wt = this.transform.worldTransform;
var a = wt.a;
var b = wt.b;
var c = wt.c;
var d = wt.d;
var tx = wt.tx;
var ty = wt.ty;
var vertexData = this.vertexData;
for (var i = 0; i < vertexData.length / 2; i++) {
var x = vertices[(i * 2)];
var y = vertices[(i * 2) + 1];
vertexData[(i * 2)] = (a * x) + (c * y) + tx;
vertexData[(i * 2) + 1] = (b * x) + (d * y) + ty;
}
if (this._roundPixels) {
var resolution = settings.RESOLUTION;
for (var i = 0; i < vertexData.length; ++i) {
vertexData[i] = Math.round((vertexData[i] * resolution | 0) / resolution);
}
}
this.vertexDirty = geometry.vertexDirtyId;
};
/**
* Updates uv field based on from geometry uv's or batchUvs
*/
Mesh.prototype.calculateUvs = function () {
var geomUvs = this.geometry.buffers[1];
if (!this.shader.uvMatrix.isSimple) {
if (!this.batchUvs) {
this.batchUvs = new MeshBatchUvs(geomUvs, this.shader.uvMatrix);
}
this.batchUvs.update();
this.uvs = this.batchUvs.data;
}
else {
this.uvs = geomUvs.data;
}
};
/**
* Updates the bounds of the mesh as a rectangle. The bounds calculation takes the worldTransform into account.
* there must be a aVertexPosition attribute present in the geometry for bounds to be calculated correctly.
*
* @protected
*/
Mesh.prototype._calculateBounds = function () {
this.calculateVertices();
this._bounds.addVertexData(this.vertexData, 0, this.vertexData.length);
};
/**
* Tests if a point is inside this mesh. Works only for PIXI.DRAW_MODES.TRIANGLES.
*
* @param {PIXI.IPoint} point the point to test
* @return {boolean} the result of the test
*/
Mesh.prototype.containsPoint = function (point) {
if (!this.getBounds().contains(point.x, point.y)) {
return false;
}
this.worldTransform.applyInverse(point, tempPoint$2);
var vertices = this.geometry.getBuffer('aVertexPosition').data;
var points = tempPolygon.points;
var indices = this.geometry.getIndex().data;
var len = indices.length;
var step = this.drawMode === 4 ? 3 : 1;
for (var i = 0; i + 2 < len; i += step) {
var ind0 = indices[i] * 2;
var ind1 = indices[i + 1] * 2;
var ind2 = indices[i + 2] * 2;
points[0] = vertices[ind0];
points[1] = vertices[ind0 + 1];
points[2] = vertices[ind1];
points[3] = vertices[ind1 + 1];
points[4] = vertices[ind2];
points[5] = vertices[ind2 + 1];
if (tempPolygon.contains(tempPoint$2.x, tempPoint$2.y)) {
return true;
}
}
return false;
};
/**
* Destroys the Mesh object.
*
* @param {object|boolean} [options] - Options parameter. A boolean will act as if all
* options have been set to that value
* @param {boolean} [options.children=false] - if set to true, all the children will have
* their destroy method called as well. 'options' will be passed on to those calls.
*/
Mesh.prototype.destroy = function (options) {
_super.prototype.destroy.call(this, options);
this.geometry.refCount--;
if (this.geometry.refCount === 0) {
this.geometry.dispose();
}
this.geometry = null;
this.shader = null;
this.state = null;
this.uvs = null;
this.indices = null;
this.vertexData = null;
};
/**
* The maximum number of vertices to consider batchable. Generally, the complexity
* of the geometry.
* @memberof PIXI.Mesh
* @static
* @member {number} BATCHABLE_SIZE
*/
Mesh.BATCHABLE_SIZE = 100;
return Mesh;
}(Container));
var fragment$8 = "varying vec2 vTextureCoord;\nuniform vec4 uColor;\n\nuniform sampler2D uSampler;\n\nvoid main(void)\n{\n gl_FragColor = texture2D(uSampler, vTextureCoord) * uColor;\n}\n";
var vertex$5 = "attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\nuniform mat3 translationMatrix;\nuniform mat3 uTextureMatrix;\n\nvarying vec2 vTextureCoord;\n\nvoid main(void)\n{\n gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n vTextureCoord = (uTextureMatrix * vec3(aTextureCoord, 1.0)).xy;\n}\n";
/**
* Slightly opinionated default shader for PixiJS 2D objects.
* @class
* @memberof PIXI
* @extends PIXI.Shader
*/
var MeshMaterial = /** @class */ (function (_super) {
__extends$a(MeshMaterial, _super);
/**
* @param {PIXI.Texture} uSampler - Texture that material uses to render.
* @param {object} [options] - Additional options
* @param {number} [options.alpha=1] - Default alpha.
* @param {number} [options.tint=0xFFFFFF] - Default tint.
* @param {string} [options.pluginName='batch'] - Renderer plugin for batching.
* @param {PIXI.Program} [options.program=0xFFFFFF] - Custom program.
* @param {object} [options.uniforms] - Custom uniforms.
*/
function MeshMaterial(uSampler, options) {
var _this = this;
var uniforms = {
uSampler: uSampler,
alpha: 1,
uTextureMatrix: Matrix.IDENTITY,
uColor: new Float32Array([1, 1, 1, 1]),
};
// Set defaults
options = Object.assign({
tint: 0xFFFFFF,
alpha: 1,
pluginName: 'batch',
}, options);
if (options.uniforms) {
Object.assign(uniforms, options.uniforms);
}
_this = _super.call(this, options.program || Program.from(vertex$5, fragment$8), uniforms) || this;
/**
* Only do update if tint or alpha changes.
* @member {boolean}
* @private
* @default false
*/
_this._colorDirty = false;
/**
* TextureMatrix instance for this Mesh, used to track Texture changes
*
* @member {PIXI.TextureMatrix}
* @readonly
*/
_this.uvMatrix = new TextureMatrix(uSampler);
/**
* `true` if shader can be batch with the renderer's batch system.
* @member {boolean}
* @default true
*/
_this.batchable = options.program === undefined;
/**
* Renderer plugin for batching
*
* @member {string}
* @default 'batch'
*/
_this.pluginName = options.pluginName;
_this.tint = options.tint;
_this.alpha = options.alpha;
return _this;
}
Object.defineProperty(MeshMaterial.prototype, "texture", {
/**
* Reference to the texture being rendered.
* @member {PIXI.Texture}
*/
get: function () {
return this.uniforms.uSampler;
},
set: function (value) {
if (this.uniforms.uSampler !== value) {
this.uniforms.uSampler = value;
this.uvMatrix.texture = value;
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(MeshMaterial.prototype, "alpha", {
get: function () {
return this._alpha;
},
/**
* This gets automatically set by the object using this.
*
* @default 1
* @member {number}
*/
set: function (value) {
if (value === this._alpha)
{ return; }
this._alpha = value;
this._colorDirty = true;
},
enumerable: true,
configurable: true
});
Object.defineProperty(MeshMaterial.prototype, "tint", {
get: function () {
return this._tint;
},
/**
* Multiply tint for the material.
* @member {number}
* @default 0xFFFFFF
*/
set: function (value) {
if (value === this._tint)
{ return; }
this._tint = value;
this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16);
this._colorDirty = true;
},
enumerable: true,
configurable: true
});
/**
* Gets called automatically by the Mesh. Intended to be overridden for custom
* MeshMaterial objects.
*/
MeshMaterial.prototype.update = function () {
if (this._colorDirty) {
this._colorDirty = false;
var baseTexture = this.texture.baseTexture;
premultiplyTintToRgba(this._tint, this._alpha, this.uniforms.uColor, baseTexture.alphaMode);
}
if (this.uvMatrix.update()) {
this.uniforms.uTextureMatrix = this.uvMatrix.mapCoord;
}
};
return MeshMaterial;
}(Shader));
/**
* Standard 2D geometry used in PixiJS.
*
* Geometry can be defined without passing in a style or data if required.
*
* ```js
* const geometry = new PIXI.Geometry();
*
* geometry.addAttribute('positions', [0, 0, 100, 0, 100, 100, 0, 100], 2);
* geometry.addAttribute('uvs', [0,0,1,0,1,1,0,1], 2);
* geometry.addIndex([0,1,2,1,3,2]);
*
* ```
* @class
* @memberof PIXI
* @extends PIXI.Geometry
*/
var MeshGeometry = /** @class */ (function (_super) {
__extends$a(MeshGeometry, _super);
/**
* @param {Float32Array|number[]} vertices - Positional data on geometry.
* @param {Float32Array|number[]} uvs - Texture UVs.
* @param {Uint16Array|number[]} index - IndexBuffer
*/
function MeshGeometry(vertices, uvs, index) {
var _this = _super.call(this) || this;
var verticesBuffer = new Buffer(vertices);
var uvsBuffer = new Buffer(uvs, true);
var indexBuffer = new Buffer(index, true, true);
_this.addAttribute('aVertexPosition', verticesBuffer, 2, false, exports.TYPES.FLOAT)
.addAttribute('aTextureCoord', uvsBuffer, 2, false, exports.TYPES.FLOAT)
.addIndex(indexBuffer);
/**
* Dirty flag to limit update calls on Mesh. For example,
* limiting updates on a single Mesh instance with a shared Geometry
* within the render loop.
* @private
* @member {number}
* @default -1
*/
_this._updateId = -1;
return _this;
}
Object.defineProperty(MeshGeometry.prototype, "vertexDirtyId", {
/**
* If the vertex position is updated.
* @member {number}
* @readonly
* @private
*/
get: function () {
return this.buffers[0]._updateID;
},
enumerable: true,
configurable: true
});
return MeshGeometry;
}(Geometry));
/*!
* @pixi/mesh-extras - v5.2.1
* Compiled Tue, 04 Feb 2020 21:48:29 UTC
*
* @pixi/mesh-extras is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
*/
var PlaneGeometry = /*@__PURE__*/(function (MeshGeometry) {
function PlaneGeometry(width, height, segWidth, segHeight)
{
if ( width === void 0 ) { width = 100; }
if ( height === void 0 ) { height = 100; }
if ( segWidth === void 0 ) { segWidth = 10; }
if ( segHeight === void 0 ) { segHeight = 10; }
MeshGeometry.call(this);
this.segWidth = segWidth;
this.segHeight = segHeight;
this.width = width;
this.height = height;
this.build();
}
if ( MeshGeometry ) { PlaneGeometry.__proto__ = MeshGeometry; }
PlaneGeometry.prototype = Object.create( MeshGeometry && MeshGeometry.prototype );
PlaneGeometry.prototype.constructor = PlaneGeometry;
/**
* Refreshes plane coordinates
* @private
*/
PlaneGeometry.prototype.build = function build ()
{
var total = this.segWidth * this.segHeight;
var verts = [];
var uvs = [];
var indices = [];
var segmentsX = this.segWidth - 1;
var segmentsY = this.segHeight - 1;
var sizeX = (this.width) / segmentsX;
var sizeY = (this.height) / segmentsY;
for (var i = 0; i < total; i++)
{
var x = (i % this.segWidth);
var y = ((i / this.segWidth) | 0);
verts.push(x * sizeX, y * sizeY);
uvs.push(x / segmentsX, y / segmentsY);
}
var totalSub = segmentsX * segmentsY;
for (var i$1 = 0; i$1 < totalSub; i$1++)
{
var xpos = i$1 % segmentsX;
var ypos = (i$1 / segmentsX) | 0;
var value = (ypos * this.segWidth) + xpos;
var value2 = (ypos * this.segWidth) + xpos + 1;
var value3 = ((ypos + 1) * this.segWidth) + xpos;
var value4 = ((ypos + 1) * this.segWidth) + xpos + 1;
indices.push(value, value2, value3,
value2, value4, value3);
}
this.buffers[0].data = new Float32Array(verts);
this.buffers[1].data = new Float32Array(uvs);
this.indexBuffer.data = new Uint16Array(indices);
// ensure that the changes are uploaded
this.buffers[0].update();
this.buffers[1].update();
this.indexBuffer.update();
};
return PlaneGeometry;
}(MeshGeometry));
/**
* RopeGeometry allows you to draw a geometry across several points and then manipulate these points.
*
* ```js
* for (let i = 0; i < 20; i++) {
* points.push(new PIXI.Point(i * 50, 0));
* };
* const rope = new PIXI.RopeGeometry(100, points);
* ```
*
* @class
* @extends PIXI.MeshGeometry
* @memberof PIXI
*
*/
var RopeGeometry = /*@__PURE__*/(function (MeshGeometry) {
function RopeGeometry(width, points, textureScale)
{
if ( width === void 0 ) { width = 200; }
if ( textureScale === void 0 ) { textureScale = 0; }
MeshGeometry.call(this, new Float32Array(points.length * 4),
new Float32Array(points.length * 4),
new Uint16Array((points.length - 1) * 6));
/**
* An array of points that determine the rope
* @member {PIXI.Point[]}
*/
this.points = points;
/**
* The width (i.e., thickness) of the rope.
* @member {number}
* @readOnly
*/
this.width = width;
/**
* Rope texture scale, if zero then the rope texture is stretched.
* @member {number}
* @readOnly
*/
this.textureScale = textureScale;
this.build();
}
if ( MeshGeometry ) { RopeGeometry.__proto__ = MeshGeometry; }
RopeGeometry.prototype = Object.create( MeshGeometry && MeshGeometry.prototype );
RopeGeometry.prototype.constructor = RopeGeometry;
/**
* Refreshes Rope indices and uvs
* @private
*/
RopeGeometry.prototype.build = function build ()
{
var points = this.points;
if (!points) { return; }
var vertexBuffer = this.getBuffer('aVertexPosition');
var uvBuffer = this.getBuffer('aTextureCoord');
var indexBuffer = this.getIndex();
// if too little points, or texture hasn't got UVs set yet just move on.
if (points.length < 1)
{
return;
}
// if the number of points has changed we will need to recreate the arraybuffers
if (vertexBuffer.data.length / 4 !== points.length)
{
vertexBuffer.data = new Float32Array(points.length * 4);
uvBuffer.data = new Float32Array(points.length * 4);
indexBuffer.data = new Uint16Array((points.length - 1) * 6);
}
var uvs = uvBuffer.data;
var indices = indexBuffer.data;
uvs[0] = 0;
uvs[1] = 0;
uvs[2] = 0;
uvs[3] = 1;
var amount = 0;
var prev = points[0];
var textureWidth = this.width * this.textureScale;
var total = points.length; // - 1;
for (var i = 0; i < total; i++)
{
// time to do some smart drawing!
var index = i * 4;
if (this.textureScale > 0)
{
// calculate pixel distance from previous point
var dx = prev.x - points[i].x;
var dy = prev.y - points[i].y;
var distance = Math.sqrt((dx * dx) + (dy * dy));
prev = points[i];
amount += distance / textureWidth;
}
else
{
// stretch texture
amount = i / (total - 1);
}
uvs[index] = amount;
uvs[index + 1] = 0;
uvs[index + 2] = amount;
uvs[index + 3] = 1;
}
var indexCount = 0;
for (var i$1 = 0; i$1 < total - 1; i$1++)
{
var index$1 = i$1 * 2;
indices[indexCount++] = index$1;
indices[indexCount++] = index$1 + 1;
indices[indexCount++] = index$1 + 2;
indices[indexCount++] = index$1 + 2;
indices[indexCount++] = index$1 + 1;
indices[indexCount++] = index$1 + 3;
}
// ensure that the changes are uploaded
uvBuffer.update();
indexBuffer.update();
this.updateVertices();
};
/**
* refreshes vertices of Rope mesh
*/
RopeGeometry.prototype.updateVertices = function updateVertices ()
{
var points = this.points;
if (points.length < 1)
{
return;
}
var lastPoint = points[0];
var nextPoint;
var perpX = 0;
var perpY = 0;
var vertices = this.buffers[0].data;
var total = points.length;
for (var i = 0; i < total; i++)
{
var point = points[i];
var index = i * 4;
if (i < points.length - 1)
{
nextPoint = points[i + 1];
}
else
{
nextPoint = point;
}
perpY = -(nextPoint.x - lastPoint.x);
perpX = nextPoint.y - lastPoint.y;
var perpLength = Math.sqrt((perpX * perpX) + (perpY * perpY));
var num = this.textureScale > 0 ? this.textureScale * this.width / 2 : this.width / 2;
perpX /= perpLength;
perpY /= perpLength;
perpX *= num;
perpY *= num;
vertices[index] = point.x + perpX;
vertices[index + 1] = point.y + perpY;
vertices[index + 2] = point.x - perpX;
vertices[index + 3] = point.y - perpY;
lastPoint = point;
}
this.buffers[0].update();
};
RopeGeometry.prototype.update = function update ()
{
if (this.textureScale > 0)
{
this.build(); // we need to update UVs
}
else
{
this.updateVertices();
}
};
return RopeGeometry;
}(MeshGeometry));
/**
* The rope allows you to draw a texture across several points and then manipulate these points
*
*```js
* for (let i = 0; i < 20; i++) {
* points.push(new PIXI.Point(i * 50, 0));
* };
* let rope = new PIXI.SimpleRope(PIXI.Texture.from("snake.png"), points);
* ```
*
* @class
* @extends PIXI.Mesh
* @memberof PIXI
*
*/
var SimpleRope = /*@__PURE__*/(function (Mesh) {
function SimpleRope(texture, points, textureScale)
{
if ( textureScale === void 0 ) { textureScale = 0; }
var ropeGeometry = new RopeGeometry(texture.height, points, textureScale);
var meshMaterial = new MeshMaterial(texture);
if (textureScale > 0)
{
// attempt to set UV wrapping, will fail on non-power of two textures
texture.baseTexture.wrapMode = exports.WRAP_MODES.REPEAT;
}
Mesh.call(this, ropeGeometry, meshMaterial);
/**
* re-calculate vertices by rope points each frame
*
* @member {boolean}
*/
this.autoUpdate = true;
}
if ( Mesh ) { SimpleRope.__proto__ = Mesh; }
SimpleRope.prototype = Object.create( Mesh && Mesh.prototype );
SimpleRope.prototype.constructor = SimpleRope;
SimpleRope.prototype._render = function _render (renderer)
{
if (this.autoUpdate
|| this.geometry.width !== this.shader.texture.height)
{
this.geometry.width = this.shader.texture.height;
this.geometry.update();
}
Mesh.prototype._render.call(this, renderer);
};
return SimpleRope;
}(Mesh));
/**
* The SimplePlane allows you to draw a texture across several points and then manipulate these points
*
*```js
* for (let i = 0; i < 20; i++) {
* points.push(new PIXI.Point(i * 50, 0));
* };
* let SimplePlane = new PIXI.SimplePlane(PIXI.Texture.from("snake.png"), points);
* ```
*
* @class
* @extends PIXI.Mesh
* @memberof PIXI
*
*/
var SimplePlane = /*@__PURE__*/(function (Mesh) {
function SimplePlane(texture, verticesX, verticesY)
{
var planeGeometry = new PlaneGeometry(texture.width, texture.height, verticesX, verticesY);
var meshMaterial = new MeshMaterial(Texture.WHITE);
Mesh.call(this, planeGeometry, meshMaterial);
// lets call the setter to ensure all necessary updates are performed
this.texture = texture;
}
if ( Mesh ) { SimplePlane.__proto__ = Mesh; }
SimplePlane.prototype = Object.create( Mesh && Mesh.prototype );
SimplePlane.prototype.constructor = SimplePlane;
var prototypeAccessors = { texture: { configurable: true } };
/**
* Method used for overrides, to do something in case texture frame was changed.
* Meshes based on plane can override it and change more details based on texture.
*/
SimplePlane.prototype.textureUpdated = function textureUpdated ()
{
this._textureID = this.shader.texture._updateID;
this.geometry.width = this.shader.texture.width;
this.geometry.height = this.shader.texture.height;
this.geometry.build();
};
prototypeAccessors.texture.set = function (value)
{
// Track texture same way sprite does.
// For generated meshes like NineSlicePlane it can change the geometry.
// Unfortunately, this method might not work if you directly change texture in material.
if (this.shader.texture === value)
{
return;
}
this.shader.texture = value;
this._textureID = -1;
if (value.baseTexture.valid)
{
this.textureUpdated();
}
else
{
value.once('update', this.textureUpdated, this);
}
};
prototypeAccessors.texture.get = function ()
{
return this.shader.texture;
};
SimplePlane.prototype._render = function _render (renderer)
{
if (this._textureID !== this.shader.texture._updateID)
{
this.textureUpdated();
}
Mesh.prototype._render.call(this, renderer);
};
Object.defineProperties( SimplePlane.prototype, prototypeAccessors );
return SimplePlane;
}(Mesh));
/**
* The Simple Mesh class mimics Mesh in PixiJS v4, providing easy-to-use constructor arguments.
* For more robust customization, use {@link PIXI.Mesh}.
*
* @class
* @extends PIXI.Mesh
* @memberof PIXI
*/
var SimpleMesh = /*@__PURE__*/(function (Mesh) {
function SimpleMesh(texture, vertices, uvs, indices, drawMode)
{
if ( texture === void 0 ) { texture = Texture.EMPTY; }
var geometry = new MeshGeometry(vertices, uvs, indices);
geometry.getBuffer('aVertexPosition').static = false;
var meshMaterial = new MeshMaterial(texture);
Mesh.call(this, geometry, meshMaterial, null, drawMode);
/**
* upload vertices buffer each frame
* @member {boolean}
*/
this.autoUpdate = true;
}
if ( Mesh ) { SimpleMesh.__proto__ = Mesh; }
SimpleMesh.prototype = Object.create( Mesh && Mesh.prototype );
SimpleMesh.prototype.constructor = SimpleMesh;
var prototypeAccessors = { vertices: { configurable: true } };
/**
* Collection of vertices data.
* @member {Float32Array}
*/
prototypeAccessors.vertices.get = function ()
{
return this.geometry.getBuffer('aVertexPosition').data;
};
prototypeAccessors.vertices.set = function (value)
{
this.geometry.getBuffer('aVertexPosition').data = value;
};
SimpleMesh.prototype._render = function _render (renderer)
{
if (this.autoUpdate)
{
this.geometry.getBuffer('aVertexPosition').update();
}
Mesh.prototype._render.call(this, renderer);
};
Object.defineProperties( SimpleMesh.prototype, prototypeAccessors );
return SimpleMesh;
}(Mesh));
var DEFAULT_BORDER_SIZE = 10;
/**
* The NineSlicePlane allows you to stretch a texture using 9-slice scaling. The corners will remain unscaled (useful
* for buttons with rounded corners for example) and the other areas will be scaled horizontally and or vertically
*
*```js
* let Plane9 = new PIXI.NineSlicePlane(PIXI.Texture.from('BoxWithRoundedCorners.png'), 15, 15, 15, 15);
* ```
*
* A B
* +---+----------------------+---+
* C | 1 | 2 | 3 |
* +---+----------------------+---+
* | | | |
* | 4 | 5 | 6 |
* | | | |
* +---+----------------------+---+
* D | 7 | 8 | 9 |
* +---+----------------------+---+
* When changing this objects width and/or height:
* areas 1 3 7 and 9 will remain unscaled.
* areas 2 and 8 will be stretched horizontally
* areas 4 and 6 will be stretched vertically
* area 5 will be stretched both horizontally and vertically
*
*
* @class
* @extends PIXI.SimplePlane
* @memberof PIXI
*
*/
var NineSlicePlane = /*@__PURE__*/(function (SimplePlane) {
function NineSlicePlane(texture, leftWidth, topHeight, rightWidth, bottomHeight)
{
SimplePlane.call(this, Texture.WHITE, 4, 4);
this._origWidth = texture.orig.width;
this._origHeight = texture.orig.height;
/**
* The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane
*
* @member {number}
* @override
*/
this._width = this._origWidth;
/**
* The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane
*
* @member {number}
* @override
*/
this._height = this._origHeight;
/**
* The width of the left column (a)
*
* @member {number}
* @private
*/
this._leftWidth = typeof leftWidth !== 'undefined' ? leftWidth : DEFAULT_BORDER_SIZE;
/**
* The width of the right column (b)
*
* @member {number}
* @private
*/
this._rightWidth = typeof rightWidth !== 'undefined' ? rightWidth : DEFAULT_BORDER_SIZE;
/**
* The height of the top row (c)
*
* @member {number}
* @private
*/
this._topHeight = typeof topHeight !== 'undefined' ? topHeight : DEFAULT_BORDER_SIZE;
/**
* The height of the bottom row (d)
*
* @member {number}
* @private
*/
this._bottomHeight = typeof bottomHeight !== 'undefined' ? bottomHeight : DEFAULT_BORDER_SIZE;
// lets call the setter to ensure all necessary updates are performed
this.texture = texture;
}
if ( SimplePlane ) { NineSlicePlane.__proto__ = SimplePlane; }
NineSlicePlane.prototype = Object.create( SimplePlane && SimplePlane.prototype );
NineSlicePlane.prototype.constructor = NineSlicePlane;
var prototypeAccessors = { vertices: { configurable: true },width: { configurable: true },height: { configurable: true },leftWidth: { configurable: true },rightWidth: { configurable: true },topHeight: { configurable: true },bottomHeight: { configurable: true } };
NineSlicePlane.prototype.textureUpdated = function textureUpdated ()
{
this._textureID = this.shader.texture._updateID;
this._refresh();
};
prototypeAccessors.vertices.get = function ()
{
return this.geometry.getBuffer('aVertexPosition').data;
};
prototypeAccessors.vertices.set = function (value)
{
this.geometry.getBuffer('aVertexPosition').data = value;
};
/**
* Updates the horizontal vertices.
*
*/
NineSlicePlane.prototype.updateHorizontalVertices = function updateHorizontalVertices ()
{
var vertices = this.vertices;
var scale = this._getMinScale();
vertices[9] = vertices[11] = vertices[13] = vertices[15] = this._topHeight * scale;
vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - (this._bottomHeight * scale);
vertices[25] = vertices[27] = vertices[29] = vertices[31] = this._height;
};
/**
* Updates the vertical vertices.
*
*/
NineSlicePlane.prototype.updateVerticalVertices = function updateVerticalVertices ()
{
var vertices = this.vertices;
var scale = this._getMinScale();
vertices[2] = vertices[10] = vertices[18] = vertices[26] = this._leftWidth * scale;
vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - (this._rightWidth * scale);
vertices[6] = vertices[14] = vertices[22] = vertices[30] = this._width;
};
/**
* Returns the smaller of a set of vertical and horizontal scale of nine slice corners.
*
* @return {number} Smaller number of vertical and horizontal scale.
* @private
*/
NineSlicePlane.prototype._getMinScale = function _getMinScale ()
{
var w = this._leftWidth + this._rightWidth;
var scaleW = this._width > w ? 1.0 : this._width / w;
var h = this._topHeight + this._bottomHeight;
var scaleH = this._height > h ? 1.0 : this._height / h;
var scale = Math.min(scaleW, scaleH);
return scale;
};
/**
* The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane
*
* @member {number}
*/
prototypeAccessors.width.get = function ()
{
return this._width;
};
prototypeAccessors.width.set = function (value) // eslint-disable-line require-jsdoc
{
this._width = value;
this._refresh();
};
/**
* The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane
*
* @member {number}
*/
prototypeAccessors.height.get = function ()
{
return this._height;
};
prototypeAccessors.height.set = function (value) // eslint-disable-line require-jsdoc
{
this._height = value;
this._refresh();
};
/**
* The width of the left column
*
* @member {number}
*/
prototypeAccessors.leftWidth.get = function ()
{
return this._leftWidth;
};
prototypeAccessors.leftWidth.set = function (value) // eslint-disable-line require-jsdoc
{
this._leftWidth = value;
this._refresh();
};
/**
* The width of the right column
*
* @member {number}
*/
prototypeAccessors.rightWidth.get = function ()
{
return this._rightWidth;
};
prototypeAccessors.rightWidth.set = function (value) // eslint-disable-line require-jsdoc
{
this._rightWidth = value;
this._refresh();
};
/**
* The height of the top row
*
* @member {number}
*/
prototypeAccessors.topHeight.get = function ()
{
return this._topHeight;
};
prototypeAccessors.topHeight.set = function (value) // eslint-disable-line require-jsdoc
{
this._topHeight = value;
this._refresh();
};
/**
* The height of the bottom row
*
* @member {number}
*/
prototypeAccessors.bottomHeight.get = function ()
{
return this._bottomHeight;
};
prototypeAccessors.bottomHeight.set = function (value) // eslint-disable-line require-jsdoc
{
this._bottomHeight = value;
this._refresh();
};
/**
* Refreshes NineSlicePlane coords. All of them.
*/
NineSlicePlane.prototype._refresh = function _refresh ()
{
var texture = this.texture;
var uvs = this.geometry.buffers[1].data;
this._origWidth = texture.orig.width;
this._origHeight = texture.orig.height;
var _uvw = 1.0 / this._origWidth;
var _uvh = 1.0 / this._origHeight;
uvs[0] = uvs[8] = uvs[16] = uvs[24] = 0;
uvs[1] = uvs[3] = uvs[5] = uvs[7] = 0;
uvs[6] = uvs[14] = uvs[22] = uvs[30] = 1;
uvs[25] = uvs[27] = uvs[29] = uvs[31] = 1;
uvs[2] = uvs[10] = uvs[18] = uvs[26] = _uvw * this._leftWidth;
uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - (_uvw * this._rightWidth);
uvs[9] = uvs[11] = uvs[13] = uvs[15] = _uvh * this._topHeight;
uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - (_uvh * this._bottomHeight);
this.updateHorizontalVertices();
this.updateVerticalVertices();
this.geometry.buffers[0].update();
this.geometry.buffers[1].update();
};
Object.defineProperties( NineSlicePlane.prototype, prototypeAccessors );
return NineSlicePlane;
}(SimplePlane));
/*!
* @pixi/sprite-animated - v5.2.1
* Compiled Tue, 04 Feb 2020 21:48:29 UTC
*
* @pixi/sprite-animated is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
*/
/**
* An AnimatedSprite is a simple way to display an animation depicted by a list of textures.
*
* ```js
* let alienImages = ["image_sequence_01.png","image_sequence_02.png","image_sequence_03.png","image_sequence_04.png"];
* let textureArray = [];
*
* for (let i=0; i < 4; i++)
* {
* let texture = PIXI.Texture.from(alienImages[i]);
* textureArray.push(texture);
* };
*
* let animatedSprite = new PIXI.AnimatedSprite(textureArray);
* ```
*
* The more efficient and simpler way to create an animated sprite is using a {@link PIXI.Spritesheet}
* containing the animation definitions:
*
* ```js
* PIXI.Loader.shared.add("assets/spritesheet.json").load(setup);
*
* function setup() {
* let sheet = PIXI.Loader.shared.resources["assets/spritesheet.json"].spritesheet;
* animatedSprite = new PIXI.AnimatedSprite(sheet.animations["image_sequence"]);
* ...
* }
* ```
*
* @class
* @extends PIXI.Sprite
* @memberof PIXI
*/
var AnimatedSprite = /*@__PURE__*/(function (Sprite) {
function AnimatedSprite(textures, autoUpdate)
{
Sprite.call(this, textures[0] instanceof Texture ? textures[0] : textures[0].texture);
/**
* @type {PIXI.Texture[]}
* @private
*/
this._textures = null;
/**
* @type {number[]}
* @private
*/
this._durations = null;
this.textures = textures;
/**
* `true` uses PIXI.Ticker.shared to auto update animation time.
* @type {boolean}
* @default true
* @private
*/
this._autoUpdate = autoUpdate !== false;
/**
* The speed that the AnimatedSprite will play at. Higher is faster, lower is slower.
*
* @member {number}
* @default 1
*/
this.animationSpeed = 1;
/**
* Whether or not the animate sprite repeats after playing.
*
* @member {boolean}
* @default true
*/
this.loop = true;
/**
* Update anchor to [Texture's defaultAnchor]{@link PIXI.Texture#defaultAnchor} when frame changes.
*
* Useful with [sprite sheet animations]{@link PIXI.Spritesheet#animations} created with tools.
* Changing anchor for each frame allows to pin sprite origin to certain moving feature
* of the frame (e.g. left foot).
*
* Note: Enabling this will override any previously set `anchor` on each frame change.
*
* @member {boolean}
* @default false
*/
this.updateAnchor = false;
/**
* Function to call when an AnimatedSprite finishes playing.
*
* @member {Function}
*/
this.onComplete = null;
/**
* Function to call when an AnimatedSprite changes which texture is being rendered.
*
* @member {Function}
*/
this.onFrameChange = null;
/**
* Function to call when `loop` is true, and an AnimatedSprite is played and loops around to start again.
*
* @member {Function}
*/
this.onLoop = null;
/**
* Elapsed time since animation has been started, used internally to display current texture.
*
* @member {number}
* @private
*/
this._currentTime = 0;
/**
* Indicates if the AnimatedSprite is currently playing.
*
* @member {boolean}
* @readonly
*/
this.playing = false;
}
if ( Sprite ) { AnimatedSprite.__proto__ = Sprite; }
AnimatedSprite.prototype = Object.create( Sprite && Sprite.prototype );
AnimatedSprite.prototype.constructor = AnimatedSprite;
var prototypeAccessors = { totalFrames: { configurable: true },textures: { configurable: true },currentFrame: { configurable: true } };
/**
* Stops the AnimatedSprite.
*
*/
AnimatedSprite.prototype.stop = function stop ()
{
if (!this.playing)
{
return;
}
this.playing = false;
if (this._autoUpdate)
{
Ticker.shared.remove(this.update, this);
}
};
/**
* Plays the AnimatedSprite.
*
*/
AnimatedSprite.prototype.play = function play ()
{
if (this.playing)
{
return;
}
this.playing = true;
if (this._autoUpdate)
{
Ticker.shared.add(this.update, this, exports.UPDATE_PRIORITY.HIGH);
}
};
/**
* Stops the AnimatedSprite and goes to a specific frame.
*
* @param {number} frameNumber - Frame index to stop at.
*/
AnimatedSprite.prototype.gotoAndStop = function gotoAndStop (frameNumber)
{
this.stop();
var previousFrame = this.currentFrame;
this._currentTime = frameNumber;
if (previousFrame !== this.currentFrame)
{
this.updateTexture();
}
};
/**
* Goes to a specific frame and begins playing the AnimatedSprite.
*
* @param {number} frameNumber - Frame index to start at.
*/
AnimatedSprite.prototype.gotoAndPlay = function gotoAndPlay (frameNumber)
{
var previousFrame = this.currentFrame;
this._currentTime = frameNumber;
if (previousFrame !== this.currentFrame)
{
this.updateTexture();
}
this.play();
};
/**
* Updates the object transform for rendering.
*
* @private
* @param {number} deltaTime - Time since last tick.
*/
AnimatedSprite.prototype.update = function update (deltaTime)
{
var elapsed = this.animationSpeed * deltaTime;
var previousFrame = this.currentFrame;
if (this._durations !== null)
{
var lag = this._currentTime % 1 * this._durations[this.currentFrame];
lag += elapsed / 60 * 1000;
while (lag < 0)
{
this._currentTime--;
lag += this._durations[this.currentFrame];
}
var sign = Math.sign(this.animationSpeed * deltaTime);
this._currentTime = Math.floor(this._currentTime);
while (lag >= this._durations[this.currentFrame])
{
lag -= this._durations[this.currentFrame] * sign;
this._currentTime += sign;
}
this._currentTime += lag / this._durations[this.currentFrame];
}
else
{
this._currentTime += elapsed;
}
if (this._currentTime < 0 && !this.loop)
{
this._currentTime = 0;
this.stop();
if (this.onComplete)
{
this.onComplete();
}
}
else if (this._currentTime >= this._textures.length && !this.loop)
{
this._currentTime = this._textures.length - 1;
this.stop();
if (this.onComplete)
{
this.onComplete();
}
}
else if (previousFrame !== this.currentFrame)
{
if (this.loop && this.onLoop)
{
if (this.animationSpeed > 0 && this.currentFrame < previousFrame)
{
this.onLoop();
}
else if (this.animationSpeed < 0 && this.currentFrame > previousFrame)
{
this.onLoop();
}
}
this.updateTexture();
}
};
/**
* Updates the displayed texture to match the current frame index.
*
* @private
*/
AnimatedSprite.prototype.updateTexture = function updateTexture ()
{
this._texture = this._textures[this.currentFrame];
this._textureID = -1;
this._textureTrimmedID = -1;
this._cachedTint = 0xFFFFFF;
this.uvs = this._texture._uvs.uvsFloat32;
if (this.updateAnchor)
{
this._anchor.copyFrom(this._texture.defaultAnchor);
}
if (this.onFrameChange)
{
this.onFrameChange(this.currentFrame);
}
};
/**
* Stops the AnimatedSprite and destroys it.
*
* @param {object|boolean} [options] - Options parameter. A boolean will act as if all options
* have been set to that value.
* @param {boolean} [options.children=false] - If set to true, all the children will have their destroy
* method called as well. 'options' will be passed on to those calls.
* @param {boolean} [options.texture=false] - Should it destroy the current texture of the sprite as well.
* @param {boolean} [options.baseTexture=false] - Should it destroy the base texture of the sprite as well.
*/
AnimatedSprite.prototype.destroy = function destroy (options)
{
this.stop();
Sprite.prototype.destroy.call(this, options);
this.onComplete = null;
this.onFrameChange = null;
this.onLoop = null;
};
/**
* A short hand way of creating an AnimatedSprite from an array of frame ids.
*
* @static
* @param {string[]} frames - The array of frames ids the AnimatedSprite will use as its texture frames.
* @return {AnimatedSprite} The new animated sprite with the specified frames.
*/
AnimatedSprite.fromFrames = function fromFrames (frames)
{
var textures = [];
for (var i = 0; i < frames.length; ++i)
{
textures.push(Texture.from(frames[i]));
}
return new AnimatedSprite(textures);
};
/**
* A short hand way of creating an AnimatedSprite from an array of image ids.
*
* @static
* @param {string[]} images - The array of image urls the AnimatedSprite will use as its texture frames.
* @return {AnimatedSprite} The new animate sprite with the specified images as frames.
*/
AnimatedSprite.fromImages = function fromImages (images)
{
var textures = [];
for (var i = 0; i < images.length; ++i)
{
textures.push(Texture.from(images[i]));
}
return new AnimatedSprite(textures);
};
/**
* The total number of frames in the AnimatedSprite. This is the same as number of textures
* assigned to the AnimatedSprite.
*
* @readonly
* @member {number}
* @default 0
*/
prototypeAccessors.totalFrames.get = function ()
{
return this._textures.length;
};
/**
* The array of textures used for this AnimatedSprite.
*
* @member {PIXI.Texture[]}
*/
prototypeAccessors.textures.get = function ()
{
return this._textures;
};
prototypeAccessors.textures.set = function (value) // eslint-disable-line require-jsdoc
{
if (value[0] instanceof Texture)
{
this._textures = value;
this._durations = null;
}
else
{
this._textures = [];
this._durations = [];
for (var i = 0; i < value.length; i++)
{
this._textures.push(value[i].texture);
this._durations.push(value[i].time);
}
}
this.gotoAndStop(0);
this.updateTexture();
};
/**
* The AnimatedSprites current frame index.
*
* @member {number}
* @readonly
*/
prototypeAccessors.currentFrame.get = function ()
{
var currentFrame = Math.floor(this._currentTime) % this._textures.length;
if (currentFrame < 0)
{
currentFrame += this._textures.length;
}
return currentFrame;
};
Object.defineProperties( AnimatedSprite.prototype, prototypeAccessors );
return AnimatedSprite;
}(Sprite));
/*!
* pixi.js - v5.2.1
* Compiled Tue, 04 Feb 2020 21:48:29 UTC
*
* pixi.js is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
*/
var v5 = '5.0.0';
/**
* Deprecations (backward compatibilities) are automatically applied for browser bundles
* in the UMD module format. If using Webpack or Rollup, you'll need to apply these
* deprecations manually by doing something like this:
* @example
* import * as PIXI from 'pixi.js';
* PIXI.useDeprecated(); // MUST be bound to namespace
* @memberof PIXI
* @function useDeprecated
*/
function useDeprecated()
{
var PIXI = this;
Object.defineProperties(PIXI, {
/**
* @constant {RegExp|string} SVG_SIZE
* @memberof PIXI
* @see PIXI.resources.SVGResource.SVG_SIZE
* @deprecated since 5.0.0
*/
SVG_SIZE: {
get: function get()
{
deprecation(v5, 'PIXI.utils.SVG_SIZE property has moved to PIXI.resources.SVGResource.SVG_SIZE');
return PIXI.SVGResource.SVG_SIZE;
},
},
/**
* @class PIXI.TransformStatic
* @deprecated since 5.0.0
* @see PIXI.Transform
*/
TransformStatic: {
get: function get()
{
deprecation(v5, 'PIXI.TransformStatic class has been removed, use PIXI.Transform');
return PIXI.Transform;
},
},
/**
* @class PIXI.TransformBase
* @deprecated since 5.0.0
* @see PIXI.Transform
*/
TransformBase: {
get: function get()
{
deprecation(v5, 'PIXI.TransformBase class has been removed, use PIXI.Transform');
return PIXI.Transform;
},
},
/**
* Constants that specify the transform type.
*
* @static
* @constant
* @name TRANSFORM_MODE
* @memberof PIXI
* @enum {number}
* @deprecated since 5.0.0
* @property {number} STATIC
* @property {number} DYNAMIC
*/
TRANSFORM_MODE: {
get: function get()
{
deprecation(v5, 'PIXI.TRANSFORM_MODE property has been removed');
return { STATIC: 0, DYNAMIC: 1 };
},
},
/**
* @class PIXI.WebGLRenderer
* @see PIXI.Renderer
* @deprecated since 5.0.0
*/
WebGLRenderer: {
get: function get()
{
deprecation(v5, 'PIXI.WebGLRenderer class has moved to PIXI.Renderer');
return PIXI.Renderer;
},
},
/**
* @class PIXI.CanvasRenderTarget
* @see PIXI.utils.CanvasRenderTarget
* @deprecated since 5.0.0
*/
CanvasRenderTarget: {
get: function get()
{
deprecation(v5, 'PIXI.CanvasRenderTarget class has moved to PIXI.utils.CanvasRenderTarget');
return PIXI.utils.CanvasRenderTarget;
},
},
/**
* @memberof PIXI
* @name loader
* @type {PIXI.Loader}
* @see PIXI.Loader.shared
* @deprecated since 5.0.0
*/
loader: {
get: function get()
{
deprecation(v5, 'PIXI.loader instance has moved to PIXI.Loader.shared');
return PIXI.Loader.shared;
},
},
/**
* @class PIXI.FilterManager
* @see PIXI.systems.FilterSystem
* @deprecated since 5.0.0
*/
FilterManager: {
get: function get()
{
deprecation(v5, 'PIXI.FilterManager class has moved to PIXI.systems.FilterSystem');
return PIXI.systems.FilterSystem;
},
},
/**
* @namespace PIXI.CanvasTinter
* @see PIXI.canvasUtils
* @deprecated since 5.2.0
*/
CanvasTinter: {
get: function get()
{
deprecation('5.2.0', 'PIXI.CanvasTinter namespace has moved to PIXI.canvasUtils');
return PIXI.canvasUtils;
},
},
/**
* @namespace PIXI.GroupD8
* @see PIXI.groupD8
* @deprecated since 5.2.0
*/
GroupD8: {
get: function get()
{
deprecation('5.2.0', 'PIXI.GroupD8 namespace has moved to PIXI.groupD8');
return PIXI.groupD8;
},
},
});
/**
* @namespace PIXI.prepare
* @see PIXI
* @deprecated since 5.2.1
*/
PIXI.prepare = {};
Object.defineProperties(PIXI.prepare, {
/**
* @class PIXI.prepare.BasePrepare
* @deprecated since 5.2.1
* @see PIXI.BasePrepare
*/
BasePrepare: {
get: function get()
{
deprecation('5.2.1', 'PIXI.prepare.BasePrepare moved to PIXI.BasePrepare');
return PIXI.BasePrepare;
},
},
/**
* @class PIXI.prepare.Prepare
* @deprecated since 5.2.1
* @see PIXI.Prepare
*/
Prepare: {
get: function get()
{
deprecation('5.2.1', 'PIXI.prepare.Prepare moved to PIXI.Prepare');
return PIXI.Prepare;
},
},
/**
* @class PIXI.prepare.CanvasPrepare
* @deprecated since 5.2.1
* @see PIXI.CanvasPrepare
*/
CanvasPrepare: {
get: function get()
{
deprecation('5.2.1', 'PIXI.prepare.CanvasPrepare moved to PIXI.CanvasPrepare');
return PIXI.CanvasPrepare;
},
},
});
/**
* @namespace PIXI.extract
* @see PIXI
* @deprecated since 5.2.1
*/
PIXI.extract = {};
Object.defineProperties(PIXI.extract, {
/**
* @class PIXI.extract.Extract
* @deprecated since 5.2.1
* @see PIXI.Extract
*/
Extract: {
get: function get()
{
deprecation('5.2.1', 'PIXI.extract.Extract moved to PIXI.Extract');
return PIXI.Extract;
},
},
/**
* @class PIXI.extract.CanvasExtract
* @deprecated since 5.2.1
* @see PIXI.CanvasExtract
*/
CanvasExtract: {
get: function get()
{
deprecation('5.2.1', 'PIXI.extract.CanvasExtract moved to PIXI.CanvasExtract');
return PIXI.CanvasExtract;
},
},
});
/**
* This namespace has been removed. All classes previous nested
* under this namespace have been moved to the top-level `PIXI` object.
* @namespace PIXI.extras
* @deprecated since 5.0.0
*/
PIXI.extras = {};
Object.defineProperties(PIXI.extras, {
/**
* @class PIXI.extras.TilingSprite
* @see PIXI.TilingSprite
* @deprecated since 5.0.0
*/
TilingSprite: {
get: function get()
{
deprecation(v5, 'PIXI.extras.TilingSprite class has moved to PIXI.TilingSprite');
return PIXI.TilingSprite;
},
},
/**
* @class PIXI.extras.TilingSpriteRenderer
* @see PIXI.TilingSpriteRenderer
* @deprecated since 5.0.0
*/
TilingSpriteRenderer: {
get: function get()
{
deprecation(v5, 'PIXI.extras.TilingSpriteRenderer class has moved to PIXI.TilingSpriteRenderer');
return PIXI.TilingSpriteRenderer;
},
},
/**
* @class PIXI.extras.AnimatedSprite
* @see PIXI.AnimatedSprite
* @deprecated since 5.0.0
*/
AnimatedSprite: {
get: function get()
{
deprecation(v5, 'PIXI.extras.AnimatedSprite class has moved to PIXI.AnimatedSprite');
return PIXI.AnimatedSprite;
},
},
/**
* @class PIXI.extras.BitmapText
* @see PIXI.BitmapText
* @deprecated since 5.0.0
*/
BitmapText: {
get: function get()
{
deprecation(v5, 'PIXI.extras.BitmapText class has moved to PIXI.BitmapText');
return PIXI.BitmapText;
},
},
});
Object.defineProperties(PIXI.utils, {
/**
* @function PIXI.utils.getSvgSize
* @see PIXI.resources.SVGResource.getSize
* @deprecated since 5.0.0
*/
getSvgSize: {
get: function get()
{
deprecation(v5, 'PIXI.utils.getSvgSize function has moved to PIXI.resources.SVGResource.getSize');
return PIXI.SVGResource.getSize;
},
},
});
/**
* All classes on this namespace have moved to the high-level `PIXI` object.
* @namespace PIXI.mesh
* @deprecated since 5.0.0
*/
PIXI.mesh = {};
Object.defineProperties(PIXI.mesh, {
/**
* @class PIXI.mesh.Mesh
* @see PIXI.SimpleMesh
* @deprecated since 5.0.0
*/
Mesh: {
get: function get()
{
deprecation(v5, 'PIXI.mesh.Mesh class has moved to PIXI.SimpleMesh');
return PIXI.SimpleMesh;
},
},
/**
* @class PIXI.mesh.NineSlicePlane
* @see PIXI.NineSlicePlane
* @deprecated since 5.0.0
*/
NineSlicePlane: {
get: function get()
{
deprecation(v5, 'PIXI.mesh.NineSlicePlane class has moved to PIXI.NineSlicePlane');
return PIXI.NineSlicePlane;
},
},
/**
* @class PIXI.mesh.Plane
* @see PIXI.SimplePlane
* @deprecated since 5.0.0
*/
Plane: {
get: function get()
{
deprecation(v5, 'PIXI.mesh.Plane class has moved to PIXI.SimplePlane');
return PIXI.SimplePlane;
},
},
/**
* @class PIXI.mesh.Rope
* @see PIXI.SimpleRope
* @deprecated since 5.0.0
*/
Rope: {
get: function get()
{
deprecation(v5, 'PIXI.mesh.Rope class has moved to PIXI.SimpleRope');
return PIXI.SimpleRope;
},
},
/**
* @class PIXI.mesh.RawMesh
* @see PIXI.Mesh
* @deprecated since 5.0.0
*/
RawMesh: {
get: function get()
{
deprecation(v5, 'PIXI.mesh.RawMesh class has moved to PIXI.Mesh');
return PIXI.Mesh;
},
},
/**
* @class PIXI.mesh.CanvasMeshRenderer
* @see PIXI.CanvasMeshRenderer
* @deprecated since 5.0.0
*/
CanvasMeshRenderer: {
get: function get()
{
deprecation(v5, 'PIXI.mesh.CanvasMeshRenderer class has moved to PIXI.CanvasMeshRenderer');
return PIXI.CanvasMeshRenderer;
},
},
/**
* @class PIXI.mesh.MeshRenderer
* @see PIXI.MeshRenderer
* @deprecated since 5.0.0
*/
MeshRenderer: {
get: function get()
{
deprecation(v5, 'PIXI.mesh.MeshRenderer class has moved to PIXI.MeshRenderer');
return PIXI.MeshRenderer;
},
},
});
/**
* This namespace has been removed and items have been moved to
* the top-level `PIXI` object.
* @namespace PIXI.particles
* @deprecated since 5.0.0
*/
PIXI.particles = {};
Object.defineProperties(PIXI.particles, {
/**
* @class PIXI.particles.ParticleContainer
* @deprecated since 5.0.0
* @see PIXI.ParticleContainer
*/
ParticleContainer: {
get: function get()
{
deprecation(v5, 'PIXI.particles.ParticleContainer class has moved to PIXI.ParticleContainer');
return PIXI.ParticleContainer;
},
},
/**
* @class PIXI.particles.ParticleRenderer
* @deprecated since 5.0.0
* @see PIXI.ParticleRenderer
*/
ParticleRenderer: {
get: function get()
{
deprecation(v5, 'PIXI.particles.ParticleRenderer class has moved to PIXI.ParticleRenderer');
return PIXI.ParticleRenderer;
},
},
});
/**
* This namespace has been removed and items have been moved to
* the top-level `PIXI` object.
* @namespace PIXI.ticker
* @deprecated since 5.0.0
*/
PIXI.ticker = {};
Object.defineProperties(PIXI.ticker, {
/**
* @class PIXI.ticker.Ticker
* @deprecated since 5.0.0
* @see PIXI.Ticker
*/
Ticker: {
get: function get()
{
deprecation(v5, 'PIXI.ticker.Ticker class has moved to PIXI.Ticker');
return PIXI.Ticker;
},
},
/**
* @name PIXI.ticker.shared
* @type {PIXI.Ticker}
* @deprecated since 5.0.0
* @see PIXI.Ticker.shared
*/
shared: {
get: function get()
{
deprecation(v5, 'PIXI.ticker.shared instance has moved to PIXI.Ticker.shared');
return PIXI.Ticker.shared;
},
},
});
/**
* All classes on this namespace have moved to the high-level `PIXI` object.
* @namespace PIXI.loaders
* @deprecated since 5.0.0
*/
PIXI.loaders = {};
Object.defineProperties(PIXI.loaders, {
/**
* @class PIXI.loaders.Loader
* @see PIXI.Loader
* @deprecated since 5.0.0
*/
Loader: {
get: function get()
{
deprecation(v5, 'PIXI.loaders.Loader class has moved to PIXI.Loader');
return PIXI.Loader;
},
},
/**
* @class PIXI.loaders.Resource
* @see PIXI.LoaderResource
* @deprecated since 5.0.0
*/
Resource: {
get: function get()
{
deprecation(v5, 'PIXI.loaders.Resource class has moved to PIXI.LoaderResource');
return PIXI.LoaderResource;
},
},
/**
* @function PIXI.loaders.bitmapFontParser
* @see PIXI.BitmapFontLoader.use
* @deprecated since 5.0.0
*/
bitmapFontParser: {
get: function get()
{
deprecation(v5, 'PIXI.loaders.bitmapFontParser function has moved to PIXI.BitmapFontLoader.use');
return PIXI.BitmapFontLoader.use;
},
},
/**
* @function PIXI.loaders.parseBitmapFontData
* @see PIXI.BitmapFontLoader.parse
* @deprecated since 5.0.0
*/
parseBitmapFontData: {
get: function get()
{
deprecation(v5, 'PIXI.loaders.parseBitmapFontData function has moved to PIXI.BitmapFontLoader.parse');
return PIXI.BitmapFontLoader.parse;
},
},
/**
* @function PIXI.loaders.spritesheetParser
* @see PIXI.SpritesheetLoader.use
* @deprecated since 5.0.0
*/
spritesheetParser: {
get: function get()
{
deprecation(v5, 'PIXI.loaders.spritesheetParser function has moved to PIXI.SpritesheetLoader.use');
return PIXI.SpritesheetLoader.use;
},
},
/**
* @function PIXI.loaders.getResourcePath
* @see PIXI.SpritesheetLoader.getResourcePath
* @deprecated since 5.0.0
*/
getResourcePath: {
get: function get()
{
deprecation(v5, 'PIXI.loaders.getResourcePath property has moved to PIXI.SpritesheetLoader.getResourcePath');
return PIXI.SpritesheetLoader.getResourcePath;
},
},
});
/**
* @function PIXI.loaders.Loader.addPixiMiddleware
* @see PIXI.Loader.registerPlugin
* @deprecated since 5.0.0
* @param {function} middleware
*/
PIXI.Loader.addPixiMiddleware = function addPixiMiddleware(middleware)
{
deprecation(v5,
'PIXI.loaders.Loader.addPixiMiddleware function is deprecated, use PIXI.loaders.Loader.registerPlugin'
);
return PIXI.loaders.Loader.registerPlugin({ use: middleware() });
};
/**
* @class PIXI.extract.WebGLExtract
* @deprecated since 5.0.0
* @see PIXI.Extract
*/
Object.defineProperty(PIXI.extract, 'WebGLExtract', {
get: function get()
{
deprecation(v5, 'PIXI.extract.WebGLExtract method has moved to PIXI.Extract');
return PIXI.Extract;
},
});
/**
* @class PIXI.prepare.WebGLPrepare
* @deprecated since 5.0.0
* @see PIXI.Prepare
*/
Object.defineProperty(PIXI.prepare, 'WebGLPrepare', {
get: function get()
{
deprecation(v5, 'PIXI.prepare.WebGLPrepare class has moved to PIXI.Prepare');
return PIXI.Prepare;
},
});
/**
* @method PIXI.Container#_renderWebGL
* @private
* @deprecated since 5.0.0
* @see PIXI.Container#render
* @param {PIXI.Renderer} renderer Instance of renderer
*/
PIXI.Container.prototype._renderWebGL = function _renderWebGL(renderer)
{
deprecation(v5, 'PIXI.Container._renderWebGL method has moved to PIXI.Container._render');
this._render(renderer);
};
/**
* @method PIXI.Container#renderWebGL
* @deprecated since 5.0.0
* @see PIXI.Container#render
* @param {PIXI.Renderer} renderer Instance of renderer
*/
PIXI.Container.prototype.renderWebGL = function renderWebGL(renderer)
{
deprecation(v5, 'PIXI.Container.renderWebGL method has moved to PIXI.Container.render');
this.render(renderer);
};
/**
* @method PIXI.DisplayObject#renderWebGL
* @deprecated since 5.0.0
* @see PIXI.DisplayObject#render
* @param {PIXI.Renderer} renderer Instance of renderer
*/
PIXI.DisplayObject.prototype.renderWebGL = function renderWebGL(renderer)
{
deprecation(v5, 'PIXI.DisplayObject.renderWebGL method has moved to PIXI.DisplayObject.render');
this.render(renderer);
};
/**
* @method PIXI.Container#renderAdvancedWebGL
* @deprecated since 5.0.0
* @see PIXI.Container#renderAdvanced
* @param {PIXI.Renderer} renderer Instance of renderer
*/
PIXI.Container.prototype.renderAdvancedWebGL = function renderAdvancedWebGL(renderer)
{
deprecation(v5, 'PIXI.Container.renderAdvancedWebGL method has moved to PIXI.Container.renderAdvanced');
this.renderAdvanced(renderer);
};
Object.defineProperties(PIXI.settings, {
/**
* Default transform type.
*
* @static
* @deprecated since 5.0.0
* @memberof PIXI.settings
* @type {PIXI.TRANSFORM_MODE}
* @default PIXI.TRANSFORM_MODE.STATIC
*/
TRANSFORM_MODE: {
get: function get()
{
deprecation(v5, 'PIXI.settings.TRANSFORM_MODE property has been removed');
return 0;
},
set: function set()
{
deprecation(v5, 'PIXI.settings.TRANSFORM_MODE property has been removed');
},
},
});
var BaseTexture = PIXI.BaseTexture;
/**
* @method loadSource
* @memberof PIXI.BaseTexture#
* @deprecated since 5.0.0
*/
BaseTexture.prototype.loadSource = function loadSource(image)
{
deprecation(v5, 'PIXI.BaseTexture.loadSource method has been deprecated');
var resource = PIXI.resources.autoDetectResource(image);
resource.internal = true;
this.setResource(resource);
this.update();
};
var baseTextureIdDeprecation = false;
Object.defineProperties(BaseTexture.prototype, {
/**
* @name PIXI.BaseTexture#hasLoaded
* @type {boolean}
* @deprecated since 5.0.0
* @readonly
* @see PIXI.BaseTexture#valid
*/
hasLoaded: {
get: function get()
{
deprecation(v5, 'PIXI.BaseTexture.hasLoaded property has been removed, use PIXI.BaseTexture.valid');
return this.valid;
},
},
/**
* @name PIXI.BaseTexture#imageUrl
* @type {string}
* @deprecated since 5.0.0
* @see PIXI.resource.ImageResource#url
*/
imageUrl: {
get: function get()
{
deprecation(v5, 'PIXI.BaseTexture.imageUrl property has been removed, use PIXI.BaseTexture.resource.url');
return this.resource && this.resource.url;
},
set: function set(imageUrl)
{
deprecation(v5, 'PIXI.BaseTexture.imageUrl property has been removed, use PIXI.BaseTexture.resource.url');
if (this.resource)
{
this.resource.url = imageUrl;
}
},
},
/**
* @name PIXI.BaseTexture#source
* @type {HTMLImageElement|HTMLCanvasElement|HTMLVideoElement|SVGElement}
* @deprecated since 5.0.0
* @readonly
* @see PIXI.resources.BaseImageResource#source
*/
source: {
get: function get()
{
deprecation(v5, 'PIXI.BaseTexture.source property has been moved, use `PIXI.BaseTexture.resource.source`');
return this.resource && this.resource.source;
},
set: function set(source)
{
deprecation(v5, 'PIXI.BaseTexture.source property has been moved, use `PIXI.BaseTexture.resource.source` '
+ 'if you want to set HTMLCanvasElement. Otherwise, create new BaseTexture.');
if (this.resource)
{
this.resource.source = source;
}
},
},
/**
* @name PIXI.BaseTexture#premultiplyAlpha
* @type {boolean}
* @deprecated since 5.2.0
* @readonly
* @see PIXI.BaseTexture#alphaMode
*/
premultiplyAlpha: {
get: function get()
{
deprecation('5.2.0', 'PIXI.BaseTexture.premultiplyAlpha property has been changed to `alphaMode`'
+ ', see `PIXI.ALPHA_MODES`');
return this.alphaMode !== 0;
},
set: function set(value)
{
deprecation('5.2.0', 'PIXI.BaseTexture.premultiplyAlpha property has been changed to `alphaMode`'
+ ', see `PIXI.ALPHA_MODES`');
this.alphaMode = Number(value);
},
},
/**
* Batch local field, stores current texture location
*
* @name PIXI.BaseTexture#_id
* @deprecated since 5.2.0
* @type {number}
* @see PIXI.BaseTexture#_batchLocation
*/
_id: {
get: function get()
{
if (!baseTextureIdDeprecation)
{
// #popelyshev: That property was a hot place, I don't want to call deprecation method on it if possible
deprecation('5.2.0', 'PIXI.BaseTexture._id batch local field has been changed to `_batchLocation`');
baseTextureIdDeprecation = true;
}
return this._batchLocation;
},
set: function set(value)
{
this._batchLocation = value;
},
},
});
/**
* @method fromImage
* @static
* @memberof PIXI.BaseTexture
* @deprecated since 5.0.0
* @see PIXI.BaseTexture.from
*/
BaseTexture.fromImage = function fromImage(canvas, crossorigin, scaleMode, scale)
{
deprecation(v5, 'PIXI.BaseTexture.fromImage method has been replaced with PIXI.BaseTexture.from');
var resourceOptions = { scale: scale, crossorigin: crossorigin };
return BaseTexture.from(canvas, { scaleMode: scaleMode, resourceOptions: resourceOptions });
};
/**
* @method fromCanvas
* @static
* @memberof PIXI.BaseTexture
* @deprecated since 5.0.0
* @see PIXI.BaseTexture.from
*/
BaseTexture.fromCanvas = function fromCanvas(canvas, scaleMode)
{
deprecation(v5, 'PIXI.BaseTexture.fromCanvas method has been replaced with PIXI.BaseTexture.from');
return BaseTexture.from(canvas, { scaleMode: scaleMode });
};
/**
* @method fromSVG
* @static
* @memberof PIXI.BaseTexture
* @deprecated since 5.0.0
* @see PIXI.BaseTexture.from
*/
BaseTexture.fromSVG = function fromSVG(canvas, crossorigin, scaleMode, scale)
{
deprecation(v5, 'PIXI.BaseTexture.fromSVG method has been replaced with PIXI.BaseTexture.from');
var resourceOptions = { scale: scale, crossorigin: crossorigin };
return BaseTexture.from(canvas, { scaleMode: scaleMode, resourceOptions: resourceOptions });
};
Object.defineProperties(PIXI.resources.ImageResource.prototype, {
/**
* @name PIXI.resources.ImageResource#premultiplyAlpha
* @type {boolean}
* @deprecated since 5.2.0
* @readonly
* @see PIXI.resources.ImageResource#alphaMode
*/
premultiplyAlpha: {
get: function get()
{
deprecation('5.2.0', 'PIXI.resources.ImageResource.premultiplyAlpha property '
+ 'has been changed to `alphaMode`, see `PIXI.ALPHA_MODES`');
return this.alphaMode !== 0;
},
set: function set(value)
{
deprecation('5.2.0', 'PIXI.resources.ImageResource.premultiplyAlpha property '
+ 'has been changed to `alphaMode`, see `PIXI.ALPHA_MODES`');
this.alphaMode = Number(value);
},
},
});
/**
* @method PIXI.Point#copy
* @deprecated since 5.0.0
* @see PIXI.Point#copyFrom
*/
PIXI.Point.prototype.copy = function copy(p)
{
deprecation(v5, 'PIXI.Point.copy method has been replaced with PIXI.Point.copyFrom');
return this.copyFrom(p);
};
/**
* @method PIXI.ObservablePoint#copy
* @deprecated since 5.0.0
* @see PIXI.ObservablePoint#copyFrom
*/
PIXI.ObservablePoint.prototype.copy = function copy(p)
{
deprecation(v5, 'PIXI.ObservablePoint.copy method has been replaced with PIXI.ObservablePoint.copyFrom');
return this.copyFrom(p);
};
/**
* @method PIXI.Rectangle#copy
* @deprecated since 5.0.0
* @see PIXI.Rectangle#copyFrom
*/
PIXI.Rectangle.prototype.copy = function copy(p)
{
deprecation(v5, 'PIXI.Rectangle.copy method has been replaced with PIXI.Rectangle.copyFrom');
return this.copyFrom(p);
};
/**
* @method PIXI.Matrix#copy
* @deprecated since 5.0.0
* @see PIXI.Matrix#copyTo
*/
PIXI.Matrix.prototype.copy = function copy(p)
{
deprecation(v5, 'PIXI.Matrix.copy method has been replaced with PIXI.Matrix.copyTo');
return this.copyTo(p);
};
/**
* @method PIXI.systems.StateSystem#setState
* @deprecated since 5.1.0
* @see PIXI.systems.StateSystem#set
*/
PIXI.systems.StateSystem.prototype.setState = function setState(s)
{
deprecation('v5.1.0', 'StateSystem.setState has been renamed to StateSystem.set');
return this.set(s);
};
Object.assign(PIXI.systems.FilterSystem.prototype, {
/**
* @method PIXI.FilterManager#getRenderTarget
* @deprecated since 5.0.0
* @see PIXI.systems.FilterSystem#getFilterTexture
*/
getRenderTarget: function getRenderTarget(clear, resolution)
{
deprecation(v5,
'PIXI.FilterManager.getRenderTarget method has been replaced with PIXI.systems.FilterSystem#getFilterTexture'
);
return this.getFilterTexture(resolution);
},
/**
* @method PIXI.FilterManager#returnRenderTarget
* @deprecated since 5.0.0
* @see PIXI.systems.FilterSystem#returnFilterTexture
*/
returnRenderTarget: function returnRenderTarget(renderTexture)
{
deprecation(v5,
'PIXI.FilterManager.returnRenderTarget method has been replaced with '
+ 'PIXI.systems.FilterSystem.returnFilterTexture'
);
this.returnFilterTexture(renderTexture);
},
/**
* @method PIXI.systems.FilterSystem#calculateScreenSpaceMatrix
* @deprecated since 5.0.0
* @param {PIXI.Matrix} outputMatrix - the matrix to output to.
* @return {PIXI.Matrix} The mapped matrix.
*/
calculateScreenSpaceMatrix: function calculateScreenSpaceMatrix(outputMatrix)
{
deprecation(v5, 'PIXI.systems.FilterSystem.calculateScreenSpaceMatrix method is removed, '
+ 'use `(vTextureCoord * inputSize.xy) + outputFrame.xy` instead');
var mappedMatrix = outputMatrix.identity();
var ref = this.activeState;
var sourceFrame = ref.sourceFrame;
var destinationFrame = ref.destinationFrame;
mappedMatrix.translate(sourceFrame.x / destinationFrame.width, sourceFrame.y / destinationFrame.height);
mappedMatrix.scale(destinationFrame.width, destinationFrame.height);
return mappedMatrix;
},
/**
* @method PIXI.systems.FilterSystem#calculateNormalizedScreenSpaceMatrix
* @deprecated since 5.0.0
* @param {PIXI.Matrix} outputMatrix - The matrix to output to.
* @return {PIXI.Matrix} The mapped matrix.
*/
calculateNormalizedScreenSpaceMatrix: function calculateNormalizedScreenSpaceMatrix(outputMatrix)
{
deprecation(v5, 'PIXI.systems.FilterManager.calculateNormalizedScreenSpaceMatrix method is removed, '
+ 'use `((vTextureCoord * inputSize.xy) + outputFrame.xy) / outputFrame.zw` instead.');
var ref = this.activeState;
var sourceFrame = ref.sourceFrame;
var destinationFrame = ref.destinationFrame;
var mappedMatrix = outputMatrix.identity();
mappedMatrix.translate(sourceFrame.x / destinationFrame.width, sourceFrame.y / destinationFrame.height);
var translateScaleX = (destinationFrame.width / sourceFrame.width);
var translateScaleY = (destinationFrame.height / sourceFrame.height);
mappedMatrix.scale(translateScaleX, translateScaleY);
return mappedMatrix;
},
});
Object.defineProperties(PIXI.RenderTexture.prototype, {
/**
* @name PIXI.RenderTexture#sourceFrame
* @type {PIXI.Rectangle}
* @deprecated since 5.0.0
* @readonly
*/
sourceFrame: {
get: function get()
{
deprecation(v5, 'PIXI.RenderTexture.sourceFrame property has been removed');
return this.filterFrame;
},
},
/**
* @name PIXI.RenderTexture#size
* @type {PIXI.Rectangle}
* @deprecated since 5.0.0
* @readonly
*/
size: {
get: function get()
{
deprecation(v5, 'PIXI.RenderTexture.size property has been removed');
return this._frame;
},
},
});
/**
* @class BlurXFilter
* @memberof PIXI.filters
* @deprecated since 5.0.0
* @see PIXI.filters.BlurFilterPass
*/
var BlurXFilter = /*@__PURE__*/(function (superclass) {
function BlurXFilter(strength, quality, resolution, kernelSize)
{
deprecation(v5, 'PIXI.filters.BlurXFilter class is deprecated, use PIXI.filters.BlurFilterPass');
superclass.call(this, true, strength, quality, resolution, kernelSize);
}
if ( superclass ) { BlurXFilter.__proto__ = superclass; }
BlurXFilter.prototype = Object.create( superclass && superclass.prototype );
BlurXFilter.prototype.constructor = BlurXFilter;
return BlurXFilter;
}(PIXI.filters.BlurFilterPass));
/**
* @class BlurYFilter
* @memberof PIXI.filters
* @deprecated since 5.0.0
* @see PIXI.filters.BlurFilterPass
*/
var BlurYFilter = /*@__PURE__*/(function (superclass) {
function BlurYFilter(strength, quality, resolution, kernelSize)
{
deprecation(v5, 'PIXI.filters.BlurYFilter class is deprecated, use PIXI.filters.BlurFilterPass');
superclass.call(this, false, strength, quality, resolution, kernelSize);
}
if ( superclass ) { BlurYFilter.__proto__ = superclass; }
BlurYFilter.prototype = Object.create( superclass && superclass.prototype );
BlurYFilter.prototype.constructor = BlurYFilter;
return BlurYFilter;
}(PIXI.filters.BlurFilterPass));
Object.assign(PIXI.filters, {
BlurXFilter: BlurXFilter,
BlurYFilter: BlurYFilter,
});
var Sprite = PIXI.Sprite;
var Texture = PIXI.Texture;
var Graphics = PIXI.Graphics;
// Support for pixi.js-legacy bifurcation
// give users a friendly assist to use legacy
if (!Graphics.prototype.generateCanvasTexture)
{
Graphics.prototype.generateCanvasTexture = function generateCanvasTexture()
{
deprecation(v5, 'PIXI.Graphics.generateCanvasTexture method is only available in "pixi.js-legacy"');
};
}
/**
* @deprecated since 5.0.0
* @member {PIXI.Graphics} PIXI.Graphics#graphicsData
* @see PIXI.Graphics#geometry
* @readonly
*/
Object.defineProperty(PIXI.Graphics.prototype, 'graphicsData', {
get: function get()
{
deprecation(v5, 'PIXI.Graphics.graphicsData property is deprecated, use PIXI.Graphics.geometry.graphicsData');
return this.geometry.graphicsData;
},
});
/**
* @deprecated since 5.0.0
* @member {PIXI.Point[]} PIXI.SimpleRope#points
* @see PIXI.Mesh#geometry
*/
Object.defineProperty(PIXI.SimpleRope.prototype, 'points', {
get: function get()
{
deprecation(v5, 'PIXI.SimpleRope.points property is deprecated, '
+ 'use PIXI.SimpleRope.geometry.points');
return this.geometry.points;
},
set: function set(value)
{
deprecation(v5, 'PIXI.SimpleRope.points property is deprecated, '
+ 'use PIXI.SimpleRope.geometry.points');
this.geometry.points = value;
},
});
// Use these to deprecate all the Sprite from* methods
function spriteFrom(name, source, crossorigin, scaleMode)
{
deprecation(v5, ("PIXI.Sprite." + name + " method is deprecated, use PIXI.Sprite.from"));
return Sprite.from(source, {
resourceOptions: {
scale: scaleMode,
crossorigin: crossorigin,
},
});
}
/**
* @deprecated since 5.0.0
* @see PIXI.Sprite.from
* @method PIXI.Sprite.fromImage
* @return {PIXI.Sprite}
*/
Sprite.fromImage = spriteFrom.bind(null, 'fromImage');
/**
* @deprecated since 5.0.0
* @method PIXI.Sprite.fromSVG
* @see PIXI.Sprite.from
* @return {PIXI.Sprite}
*/
Sprite.fromSVG = spriteFrom.bind(null, 'fromSVG');
/**
* @deprecated since 5.0.0
* @method PIXI.Sprite.fromCanvas
* @see PIXI.Sprite.from
* @return {PIXI.Sprite}
*/
Sprite.fromCanvas = spriteFrom.bind(null, 'fromCanvas');
/**
* @deprecated since 5.0.0
* @method PIXI.Sprite.fromVideo
* @see PIXI.Sprite.from
* @return {PIXI.Sprite}
*/
Sprite.fromVideo = spriteFrom.bind(null, 'fromVideo');
/**
* @deprecated since 5.0.0
* @method PIXI.Sprite.fromFrame
* @see PIXI.Sprite.from
* @return {PIXI.Sprite}
*/
Sprite.fromFrame = spriteFrom.bind(null, 'fromFrame');
// Use these to deprecate all the Texture from* methods
function textureFrom(name, source, crossorigin, scaleMode)
{
deprecation(v5, ("PIXI.Texture." + name + " method is deprecated, use PIXI.Texture.from"));
return Texture.from(source, {
resourceOptions: {
scale: scaleMode,
crossorigin: crossorigin,
},
});
}
/**
* @deprecated since 5.0.0
* @method PIXI.Texture.fromImage
* @see PIXI.Texture.from
* @return {PIXI.Texture}
*/
Texture.fromImage = textureFrom.bind(null, 'fromImage');
/**
* @deprecated since 5.0.0
* @method PIXI.Texture.fromSVG
* @see PIXI.Texture.from
* @return {PIXI.Texture}
*/
Texture.fromSVG = textureFrom.bind(null, 'fromSVG');
/**
* @deprecated since 5.0.0
* @method PIXI.Texture.fromCanvas
* @see PIXI.Texture.from
* @return {PIXI.Texture}
*/
Texture.fromCanvas = textureFrom.bind(null, 'fromCanvas');
/**
* @deprecated since 5.0.0
* @method PIXI.Texture.fromVideo
* @see PIXI.Texture.from
* @return {PIXI.Texture}
*/
Texture.fromVideo = textureFrom.bind(null, 'fromVideo');
/**
* @deprecated since 5.0.0
* @method PIXI.Texture.fromFrame
* @see PIXI.Texture.from
* @return {PIXI.Texture}
*/
Texture.fromFrame = textureFrom.bind(null, 'fromFrame');
/**
* @deprecated since 5.0.0
* @member {boolean} PIXI.AbstractRenderer#autoResize
* @see PIXI.AbstractRenderer#autoDensity
*/
Object.defineProperty(PIXI.AbstractRenderer.prototype, 'autoResize', {
get: function get()
{
deprecation(v5, 'PIXI.AbstractRenderer.autoResize property is deprecated, '
+ 'use PIXI.AbstractRenderer.autoDensity');
return this.autoDensity;
},
set: function set(value)
{
deprecation(v5, 'PIXI.AbstractRenderer.autoResize property is deprecated, '
+ 'use PIXI.AbstractRenderer.autoDensity');
this.autoDensity = value;
},
});
/**
* @deprecated since 5.0.0
* @member {PIXI.systems.TextureSystem} PIXI.Renderer#textureManager
* @see PIXI.Renderer#texture
*/
Object.defineProperty(PIXI.Renderer.prototype, 'textureManager', {
get: function get()
{
deprecation(v5, 'PIXI.Renderer.textureManager property is deprecated, use PIXI.Renderer.texture');
return this.texture;
},
});
/**
* @namespace PIXI.utils.mixins
* @deprecated since 5.0.0
*/
PIXI.utils.mixins = {
/**
* @memberof PIXI.utils.mixins
* @function mixin
* @deprecated since 5.0.0
*/
mixin: function mixin()
{
deprecation(v5, 'PIXI.utils.mixins.mixin function is no longer available');
},
/**
* @memberof PIXI.utils.mixins
* @function delayMixin
* @deprecated since 5.0.0
*/
delayMixin: function delayMixin()
{
deprecation(v5, 'PIXI.utils.mixins.delayMixin function is no longer available');
},
/**
* @memberof PIXI.utils.mixins
* @function performMixins
* @deprecated since 5.0.0
*/
performMixins: function performMixins()
{
deprecation(v5, 'PIXI.utils.mixins.performMixins function is no longer available');
},
};
}
// Install renderer plugins
Renderer.registerPlugin('accessibility', AccessibilityManager);
Renderer.registerPlugin('extract', Extract);
Renderer.registerPlugin('interaction', InteractionManager);
Renderer.registerPlugin('particle', ParticleRenderer);
Renderer.registerPlugin('prepare', Prepare);
Renderer.registerPlugin('batch', BatchRenderer);
Renderer.registerPlugin('tilingSprite', TilingSpriteRenderer);
Loader$1.registerPlugin(BitmapFontLoader);
Loader$1.registerPlugin(SpritesheetLoader);
Application.registerPlugin(TickerPlugin);
Application.registerPlugin(AppLoaderPlugin);
/**
* String of the current PIXI version.
*
* @static
* @constant
* @memberof PIXI
* @name VERSION
* @type {string}
*/
var VERSION$1 = '5.2.1';
/**
* @namespace PIXI
*/
/**
* This namespace contains WebGL-only display filters that can be applied
* to DisplayObjects using the {@link PIXI.DisplayObject#filters filters} property.
*
* Since PixiJS only had a handful of built-in filters, additional filters
* can be downloaded {@link https://github.com/pixijs/pixi-filters here} from the
* PixiJS Filters repository.
*
* All filters must extend {@link PIXI.Filter}.
*
* @example
* // Create a new application
* const app = new PIXI.Application();
*
* // Draw a green rectangle
* const rect = new PIXI.Graphics()
* .beginFill(0x00ff00)
* .drawRect(40, 40, 200, 200);
*
* // Add a blur filter
* rect.filters = [new PIXI.filters.BlurFilter()];
*
* // Display rectangle
* app.stage.addChild(rect);
* document.body.appendChild(app.view);
* @namespace PIXI.filters
*/
var filters = {
AlphaFilter: AlphaFilter,
BlurFilter: BlurFilter,
BlurFilterPass: BlurFilterPass,
ColorMatrixFilter: ColorMatrixFilter,
DisplacementFilter: DisplacementFilter,
FXAAFilter: FXAAFilter,
NoiseFilter: NoiseFilter,
};
/*!
* @pixi/canvas-renderer - v5.2.1
* Compiled Tue, 04 Feb 2020 21:48:29 UTC
*
* @pixi/canvas-renderer is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
*/
/**
* A set of functions used to handle masking.
*
* Sprite masking is not supported on the CanvasRenderer.
*
* @class
* @memberof PIXI
*/
var CanvasMaskManager = function CanvasMaskManager(renderer)
{
this.renderer = renderer;
this._foundShapes = [];
};
/**
* This method adds it to the current stack of masks.
*
* @param {PIXI.MaskData | PIXI.Graphics} maskData - the maskData that will be pushed
*/
CanvasMaskManager.prototype.pushMask = function pushMask (maskData)
{
var renderer = this.renderer;
var maskObject = maskData.isMaskData ? maskData.maskObject : maskData;
renderer.context.save();
// TODO support sprite alpha masks??
// lots of effort required. If demand is great enough..
var foundShapes = this._foundShapes;
this.recursiveFindShapes(maskObject, foundShapes);
if (foundShapes.length > 0)
{
var context = renderer.context;
var resolution = renderer.resolution;
context.beginPath();
for (var i = 0; i < foundShapes.length; i++)
{
var shape = foundShapes[i];
var transform = shape.transform.worldTransform;
this.renderer.context.setTransform(
transform.a * resolution,
transform.b * resolution,
transform.c * resolution,
transform.d * resolution,
transform.tx * resolution,
transform.ty * resolution
);
this.renderGraphicsShape(shape);
}
foundShapes.length = 0;
context.clip();
}
};
/**
* Renders all PIXI.Graphics shapes in a subtree.
*
* @param {PIXI.Container} container - container to scan.
* @param {PIXI.Graphics[]} out - where to put found shapes
*/
CanvasMaskManager.prototype.recursiveFindShapes = function recursiveFindShapes (container, out)
{
if (container.geometry && container.geometry.graphicsData)
{
out.push(container);
}
var children = container.children;
if (children)
{
for (var i = 0; i < children.length; i++)
{
this.recursiveFindShapes(children[i], out);
}
}
};
/**
* Renders a PIXI.Graphics shape.
*
* @param {PIXI.Graphics} graphics - The object to render.
*/
CanvasMaskManager.prototype.renderGraphicsShape = function renderGraphicsShape (graphics)
{
graphics.finishPoly();
var context = this.renderer.context;
var graphicsData = graphics.geometry.graphicsData;
var len = graphicsData.length;
if (len === 0)
{
return;
}
for (var i = 0; i < len; i++)
{
var data = graphicsData[i];
var shape = data.shape;
if (data.type === exports.SHAPES.POLY)
{
var points = shape.points;
context.moveTo(points[0], points[1]);
for (var j = 1; j < points.length / 2; j++)
{
context.lineTo(points[j * 2], points[(j * 2) + 1]);
}
// if the first and last point are the same close the path - much neater :)
if (points[0] === points[points.length - 2] && points[1] === points[points.length - 1])
{
context.closePath();
}
}
else if (data.type === exports.SHAPES.RECT)
{
context.rect(shape.x, shape.y, shape.width, shape.height);
context.closePath();
}
else if (data.type === exports.SHAPES.CIRC)
{
// TODO - need to be Undefined!
context.arc(shape.x, shape.y, shape.radius, 0, 2 * Math.PI);
context.closePath();
}
else if (data.type === exports.SHAPES.ELIP)
{
// ellipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas
var w = shape.width * 2;
var h = shape.height * 2;
var x = shape.x - (w / 2);
var y = shape.y - (h / 2);
var kappa = 0.5522848;
var ox = (w / 2) * kappa; // control point offset horizontal
var oy = (h / 2) * kappa; // control point offset vertical
var xe = x + w; // x-end
var ye = y + h; // y-end
var xm = x + (w / 2); // x-middle
var ym = y + (h / 2); // y-middle
context.moveTo(x, ym);
context.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y);
context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);
context.closePath();
}
else if (data.type === exports.SHAPES.RREC)
{
var rx = shape.x;
var ry = shape.y;
var width = shape.width;
var height = shape.height;
var radius = shape.radius;
var maxRadius = Math.min(width, height) / 2 | 0;
radius = radius > maxRadius ? maxRadius : radius;
context.moveTo(rx, ry + radius);
context.lineTo(rx, ry + height - radius);
context.quadraticCurveTo(rx, ry + height, rx + radius, ry + height);
context.lineTo(rx + width - radius, ry + height);
context.quadraticCurveTo(rx + width, ry + height, rx + width, ry + height - radius);
context.lineTo(rx + width, ry + radius);
context.quadraticCurveTo(rx + width, ry, rx + width - radius, ry);
context.lineTo(rx + radius, ry);
context.quadraticCurveTo(rx, ry, rx, ry + radius);
context.closePath();
}
}
};
/**
* Restores the current drawing context to the state it was before the mask was applied.
*
* @param {PIXI.CanvasRenderer} renderer - The renderer context to use.
*/
CanvasMaskManager.prototype.popMask = function popMask (renderer)
{
renderer.context.restore();
renderer.invalidateBlendMode();
};
/**
* Destroys this canvas mask manager.
*
*/
CanvasMaskManager.prototype.destroy = function destroy ()
{
/* empty */
};
/**
* Creates a little colored canvas
*
* @ignore
* @param {string} color - The color to make the canvas
* @return {canvas} a small canvas element
*/
function createColoredCanvas(color)
{
var canvas = document.createElement('canvas');
canvas.width = 6;
canvas.height = 1;
var context = canvas.getContext('2d');
context.fillStyle = color;
context.fillRect(0, 0, 6, 1);
return canvas;
}
/**
* Checks whether the Canvas BlendModes are supported by the current browser
*
* @private
* @return {boolean} whether they are supported
*/
function canUseNewCanvasBlendModes()
{
if (typeof document === 'undefined')
{
return false;
}
var magenta = createColoredCanvas('#ff00ff');
var yellow = createColoredCanvas('#ffff00');
var canvas = document.createElement('canvas');
canvas.width = 6;
canvas.height = 1;
var context = canvas.getContext('2d');
context.globalCompositeOperation = 'multiply';
context.drawImage(magenta, 0, 0);
context.drawImage(yellow, 2, 0);
var imageData = context.getImageData(2, 0, 1, 1);
if (!imageData)
{
return false;
}
var data = imageData.data;
return (data[0] === 255 && data[1] === 0 && data[2] === 0);
}
/**
* Maps blend combinations to Canvas.
*
* @memberof PIXI
* @function mapCanvasBlendModesToPixi
* @private
* @param {string[]} [array=[]] - The array to output into.
* @return {string[]} Mapped modes.
*/
function mapCanvasBlendModesToPixi(array)
{
if ( array === void 0 ) { array = []; }
if (canUseNewCanvasBlendModes())
{
array[exports.BLEND_MODES.NORMAL] = 'source-over';
array[exports.BLEND_MODES.ADD] = 'lighter'; // IS THIS OK???
array[exports.BLEND_MODES.MULTIPLY] = 'multiply';
array[exports.BLEND_MODES.SCREEN] = 'screen';
array[exports.BLEND_MODES.OVERLAY] = 'overlay';
array[exports.BLEND_MODES.DARKEN] = 'darken';
array[exports.BLEND_MODES.LIGHTEN] = 'lighten';
array[exports.BLEND_MODES.COLOR_DODGE] = 'color-dodge';
array[exports.BLEND_MODES.COLOR_BURN] = 'color-burn';
array[exports.BLEND_MODES.HARD_LIGHT] = 'hard-light';
array[exports.BLEND_MODES.SOFT_LIGHT] = 'soft-light';
array[exports.BLEND_MODES.DIFFERENCE] = 'difference';
array[exports.BLEND_MODES.EXCLUSION] = 'exclusion';
array[exports.BLEND_MODES.HUE] = 'hue';
array[exports.BLEND_MODES.SATURATION] = 'saturate';
array[exports.BLEND_MODES.COLOR] = 'color';
array[exports.BLEND_MODES.LUMINOSITY] = 'luminosity';
}
else
{
// this means that the browser does not support the cool new blend modes in canvas 'cough' ie 'cough'
array[exports.BLEND_MODES.NORMAL] = 'source-over';
array[exports.BLEND_MODES.ADD] = 'lighter'; // IS THIS OK???
array[exports.BLEND_MODES.MULTIPLY] = 'source-over';
array[exports.BLEND_MODES.SCREEN] = 'source-over';
array[exports.BLEND_MODES.OVERLAY] = 'source-over';
array[exports.BLEND_MODES.DARKEN] = 'source-over';
array[exports.BLEND_MODES.LIGHTEN] = 'source-over';
array[exports.BLEND_MODES.COLOR_DODGE] = 'source-over';
array[exports.BLEND_MODES.COLOR_BURN] = 'source-over';
array[exports.BLEND_MODES.HARD_LIGHT] = 'source-over';
array[exports.BLEND_MODES.SOFT_LIGHT] = 'source-over';
array[exports.BLEND_MODES.DIFFERENCE] = 'source-over';
array[exports.BLEND_MODES.EXCLUSION] = 'source-over';
array[exports.BLEND_MODES.HUE] = 'source-over';
array[exports.BLEND_MODES.SATURATION] = 'source-over';
array[exports.BLEND_MODES.COLOR] = 'source-over';
array[exports.BLEND_MODES.LUMINOSITY] = 'source-over';
}
// not-premultiplied, only for webgl
array[exports.BLEND_MODES.NORMAL_NPM] = array[exports.BLEND_MODES.NORMAL];
array[exports.BLEND_MODES.ADD_NPM] = array[exports.BLEND_MODES.ADD];
array[exports.BLEND_MODES.SCREEN_NPM] = array[exports.BLEND_MODES.SCREEN];
// composite operations
array[exports.BLEND_MODES.SRC_IN] = 'source-in';
array[exports.BLEND_MODES.SRC_OUT] = 'source-out';
array[exports.BLEND_MODES.SRC_ATOP] = 'source-atop';
array[exports.BLEND_MODES.DST_OVER] = 'destination-over';
array[exports.BLEND_MODES.DST_IN] = 'destination-in';
array[exports.BLEND_MODES.DST_OUT] = 'destination-out';
array[exports.BLEND_MODES.DST_ATOP] = 'destination-atop';
array[exports.BLEND_MODES.XOR] = 'xor';
// SUBTRACT from flash, does not exist in canvas
array[exports.BLEND_MODES.SUBTRACT] = 'source-over';
return array;
}
/**
* The CanvasRenderer draws the scene and all its content onto a 2d canvas.
*
* This renderer should be used for browsers that do not support WebGL.
* Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything!
*
* @class
* @memberof PIXI
* @extends PIXI.AbstractRenderer
*/
var CanvasRenderer = /*@__PURE__*/(function (AbstractRenderer) {
function CanvasRenderer(options, arg2, arg3)
{
AbstractRenderer.call(this, exports.RENDERER_TYPE.CANVAS, options, arg2, arg3);
/**
* The root canvas 2d context that everything is drawn with.
*
* @member {CanvasRenderingContext2D}
*/
this.rootContext = this.view.getContext('2d', { alpha: this.transparent });
/**
* The currently active canvas 2d context (could change with renderTextures)
*
* @member {CanvasRenderingContext2D}
*/
this.context = this.rootContext;
/**
* Boolean flag controlling canvas refresh.
*
* @member {boolean}
*/
this.refresh = true;
/**
* Instance of a CanvasMaskManager, handles masking when using the canvas renderer.
*
* @member {PIXI.CanvasMaskManager}
*/
this.maskManager = new CanvasMaskManager(this);
/**
* The canvas property used to set the canvas smoothing property.
*
* @member {string}
*/
this.smoothProperty = 'imageSmoothingEnabled';
if (!this.rootContext.imageSmoothingEnabled)
{
if (this.rootContext.webkitImageSmoothingEnabled)
{
this.smoothProperty = 'webkitImageSmoothingEnabled';
}
else if (this.rootContext.mozImageSmoothingEnabled)
{
this.smoothProperty = 'mozImageSmoothingEnabled';
}
else if (this.rootContext.oImageSmoothingEnabled)
{
this.smoothProperty = 'oImageSmoothingEnabled';
}
else if (this.rootContext.msImageSmoothingEnabled)
{
this.smoothProperty = 'msImageSmoothingEnabled';
}
}
this.initPlugins(CanvasRenderer.__plugins);
/**
* Tracks the blend modes useful for this renderer.
*
* @member {object}
*/
this.blendModes = mapCanvasBlendModesToPixi();
this._activeBlendMode = null;
this._outerBlend = false;
this.renderingToScreen = false;
sayHello('Canvas');
/**
* Fired after rendering finishes.
*
* @event PIXI.CanvasRenderer#postrender
*/
/**
* Fired before rendering starts.
*
* @event PIXI.CanvasRenderer#prerender
*/
this.resize(this.options.width, this.options.height);
}
if ( AbstractRenderer ) { CanvasRenderer.__proto__ = AbstractRenderer; }
CanvasRenderer.prototype = Object.create( AbstractRenderer && AbstractRenderer.prototype );
CanvasRenderer.prototype.constructor = CanvasRenderer;
/**
* Renders the object to this canvas view
*
* @param {PIXI.DisplayObject} displayObject - The object to be rendered
* @param {PIXI.RenderTexture} [renderTexture] - A render texture to be rendered to.
* If unset, it will render to the root context.
* @param {boolean} [clear=false] - Whether to clear the canvas before drawing
* @param {PIXI.Matrix} [transform] - A transformation to be applied
* @param {boolean} [skipUpdateTransform=false] - Whether to skip the update transform
*/
CanvasRenderer.prototype.render = function render (displayObject, renderTexture, clear, transform, skipUpdateTransform)
{
if (!this.view)
{
return;
}
// can be handy to know!
this.renderingToScreen = !renderTexture;
this.emit('prerender');
var rootResolution = this.resolution;
if (renderTexture)
{
renderTexture = renderTexture.baseTexture || renderTexture;
if (!renderTexture._canvasRenderTarget)
{
renderTexture._canvasRenderTarget = new CanvasRenderTarget(
renderTexture.width,
renderTexture.height,
renderTexture.resolution
);
renderTexture.resource = new index.CanvasResource(renderTexture._canvasRenderTarget.canvas);
renderTexture.valid = true;
}
this.context = renderTexture._canvasRenderTarget.context;
this.resolution = renderTexture._canvasRenderTarget.resolution;
}
else
{
this.context = this.rootContext;
}
var context = this.context;
if (!renderTexture)
{
this._lastObjectRendered = displayObject;
}
if (!skipUpdateTransform)
{
// update the scene graph
var cacheParent = displayObject.parent;
var tempWt = this._tempDisplayObjectParent.transform.worldTransform;
if (transform)
{
transform.copyTo(tempWt);
// Canvas Renderer doesn't use "context.translate"
// nor does it store current translation in projectionSystem
// we re-calculate all matrices,
// its not like CanvasRenderer can survive more than 1000 elements
displayObject.transform._parentID = -1;
}
else
{
// in this case matrix cache in displayObject works like expected
tempWt.identity();
}
displayObject.parent = this._tempDisplayObjectParent;
displayObject.updateTransform();
displayObject.parent = cacheParent;
if (transform)
{
// Clear the matrix cache one more time,
// we dont have our computations to affect standard "transform=null" case
displayObject.transform._parentID = -1;
}
// displayObject.hitArea = //TODO add a temp hit area
}
context.save();
context.setTransform(1, 0, 0, 1, 0, 0);
context.globalAlpha = 1;
this._activeBlendMode = exports.BLEND_MODES.NORMAL;
this._outerBlend = false;
context.globalCompositeOperation = this.blendModes[exports.BLEND_MODES.NORMAL];
if (clear !== undefined ? clear : this.clearBeforeRender)
{
if (this.renderingToScreen)
{
if (this.transparent)
{
context.clearRect(0, 0, this.width, this.height);
}
else
{
context.fillStyle = this._backgroundColorString;
context.fillRect(0, 0, this.width, this.height);
}
} // else {
// TODO: implement background for CanvasRenderTarget or RenderTexture?
// }
}
// TODO RENDER TARGET STUFF HERE..
var tempContext = this.context;
this.context = context;
displayObject.renderCanvas(this);
this.context = tempContext;
context.restore();
this.resolution = rootResolution;
this.emit('postrender');
};
/**
* Clear the canvas of renderer.
*
* @param {string} [clearColor] - Clear the canvas with this color, except the canvas is transparent.
*/
CanvasRenderer.prototype.clear = function clear (clearColor)
{
var context = this.context;
clearColor = clearColor || this._backgroundColorString;
if (!this.transparent && clearColor)
{
context.fillStyle = clearColor;
context.fillRect(0, 0, this.width, this.height);
}
else
{
context.clearRect(0, 0, this.width, this.height);
}
};
/**
* Sets the blend mode of the renderer.
*
* @param {number} blendMode - See {@link PIXI.BLEND_MODES} for valid values.
* @param {boolean} [readyForOuterBlend=false] - Some blendModes are dangerous, they affect outer space of sprite.
* Pass `true` only if you are ready to use them.
*/
CanvasRenderer.prototype.setBlendMode = function setBlendMode (blendMode, readyForOuterBlend)
{
var outerBlend = blendMode === exports.BLEND_MODES.SRC_IN
|| blendMode === exports.BLEND_MODES.SRC_OUT
|| blendMode === exports.BLEND_MODES.DST_IN
|| blendMode === exports.BLEND_MODES.DST_ATOP;
if (!readyForOuterBlend && outerBlend)
{
blendMode = exports.BLEND_MODES.NORMAL;
}
if (this._activeBlendMode === blendMode)
{
return;
}
this._activeBlendMode = blendMode;
this._outerBlend = outerBlend;
this.context.globalCompositeOperation = this.blendModes[blendMode];
};
/**
* Removes everything from the renderer and optionally removes the Canvas DOM element.
*
* @param {boolean} [removeView=false] - Removes the Canvas element from the DOM.
*/
CanvasRenderer.prototype.destroy = function destroy (removeView)
{
// call the base destroy
AbstractRenderer.prototype.destroy.call(this, removeView);
this.context = null;
this.refresh = true;
this.maskManager.destroy();
this.maskManager = null;
this.smoothProperty = null;
};
/**
* Resizes the canvas view to the specified width and height.
*
* @extends PIXI.AbstractRenderer#resize
*
* @param {number} screenWidth - the new width of the screen
* @param {number} screenHeight - the new height of the screen
*/
CanvasRenderer.prototype.resize = function resize (screenWidth, screenHeight)
{
AbstractRenderer.prototype.resize.call(this, screenWidth, screenHeight);
// reset the scale mode.. oddly this seems to be reset when the canvas is resized.
// surely a browser bug?? Let PixiJS fix that for you..
if (this.smoothProperty)
{
this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === exports.SCALE_MODES.LINEAR);
}
};
/**
* Checks if blend mode has changed.
*/
CanvasRenderer.prototype.invalidateBlendMode = function invalidateBlendMode ()
{
this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation);
};
/**
* Collection of installed plugins. These are included by default in PIXI, but can be excluded
* by creating a custom build. Consult the README for more information about creating custom
* builds and excluding plugins.
* @name PIXI.CanvasRenderer#plugins
* @type {object}
* @readonly
* @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements.
* @property {PIXI.CanvasExtract} extract Extract image data from renderer.
* @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events.
* @property {PIXI.CanvasPrepare} prepare Pre-render display objects.
*/
/**
* Adds a plugin to the renderer.
*
* @method
* @param {string} pluginName - The name of the plugin.
* @param {Function} ctor - The constructor function or class for the plugin.
*/
CanvasRenderer.registerPlugin = function registerPlugin (pluginName, ctor)
{
CanvasRenderer.__plugins = CanvasRenderer.__plugins || {};
CanvasRenderer.__plugins[pluginName] = ctor;
};
return CanvasRenderer;
}(AbstractRenderer));
/**
* Utility methods for Sprite/Texture tinting.
*
* Tinting with the CanvasRenderer involves creating a new canvas to use as a texture,
* so be aware of the performance implications.
*
* @namespace PIXI.canvasUtils
* @memberof PIXI
*/
var canvasUtils = {
/**
* Basically this method just needs a sprite and a color and tints the sprite with the given color.
*
* @memberof PIXI.canvasUtils
* @param {PIXI.Sprite} sprite - the sprite to tint
* @param {number} color - the color to use to tint the sprite with
* @return {HTMLCanvasElement} The tinted canvas
*/
getTintedCanvas: function (sprite, color) {
var texture = sprite.texture;
color = canvasUtils.roundColor(color);
var stringColor = "#" + ((("00000" + ((color | 0).toString(16)))).substr(-6));
texture.tintCache = texture.tintCache || {};
var cachedCanvas = texture.tintCache[stringColor];
var canvas;
if (cachedCanvas)
{
if (cachedCanvas.tintId === texture._updateID)
{
return texture.tintCache[stringColor];
}
canvas = texture.tintCache[stringColor];
}
else
{
canvas = canvasUtils.canvas || document.createElement('canvas');
}
canvasUtils.tintMethod(texture, color, canvas);
canvas.tintId = texture._updateID;
if (canvasUtils.convertTintToImage)
{
// is this better?
var tintImage = new Image();
tintImage.src = canvas.toDataURL();
texture.tintCache[stringColor] = tintImage;
}
else
{
texture.tintCache[stringColor] = canvas;
// if we are not converting the texture to an image then we need to lose the reference to the canvas
canvasUtils.canvas = null;
}
return canvas;
},
/**
* Tint a texture using the 'multiply' operation.
*
* @memberof PIXI.canvasUtils
* @param {PIXI.Texture} texture - the texture to tint
* @param {number} color - the color to use to tint the sprite with
* @param {HTMLCanvasElement} canvas - the current canvas
*/
tintWithMultiply: function (texture, color, canvas) {
var context = canvas.getContext('2d');
var crop = texture._frame.clone();
var resolution = texture.baseTexture.resolution;
crop.x *= resolution;
crop.y *= resolution;
crop.width *= resolution;
crop.height *= resolution;
canvas.width = Math.ceil(crop.width);
canvas.height = Math.ceil(crop.height);
context.save();
context.fillStyle = "#" + ((("00000" + ((color | 0).toString(16)))).substr(-6));
context.fillRect(0, 0, crop.width, crop.height);
context.globalCompositeOperation = 'multiply';
var source = texture.baseTexture.getDrawableSource();
context.drawImage(
source,
crop.x,
crop.y,
crop.width,
crop.height,
0,
0,
crop.width,
crop.height
);
context.globalCompositeOperation = 'destination-atop';
context.drawImage(
source,
crop.x,
crop.y,
crop.width,
crop.height,
0,
0,
crop.width,
crop.height
);
context.restore();
},
/**
* Tint a texture using the 'overlay' operation.
*
* @memberof PIXI.canvasUtils
* @param {PIXI.Texture} texture - the texture to tint
* @param {number} color - the color to use to tint the sprite with
* @param {HTMLCanvasElement} canvas - the current canvas
*/
tintWithOverlay: function tintWithOverlay(texture, color, canvas)
{
var context = canvas.getContext('2d');
var crop = texture._frame.clone();
var resolution = texture.baseTexture.resolution;
crop.x *= resolution;
crop.y *= resolution;
crop.width *= resolution;
crop.height *= resolution;
canvas.width = Math.ceil(crop.width);
canvas.height = Math.ceil(crop.height);
context.save();
context.globalCompositeOperation = 'copy';
context.fillStyle = "#" + ((("00000" + ((color | 0).toString(16)))).substr(-6));
context.fillRect(0, 0, crop.width, crop.height);
context.globalCompositeOperation = 'destination-atop';
context.drawImage(
texture.baseTexture.getDrawableSource(),
crop.x,
crop.y,
crop.width,
crop.height,
0,
0,
crop.width,
crop.height
);
// context.globalCompositeOperation = 'copy';
context.restore();
},
/**
* Tint a texture pixel per pixel.
*
* @memberof PIXI.canvasUtils
* @param {PIXI.Texture} texture - the texture to tint
* @param {number} color - the color to use to tint the sprite with
* @param {HTMLCanvasElement} canvas - the current canvas
*/
tintWithPerPixel: function (texture, color, canvas) {
var context = canvas.getContext('2d');
var crop = texture._frame.clone();
var resolution = texture.baseTexture.resolution;
crop.x *= resolution;
crop.y *= resolution;
crop.width *= resolution;
crop.height *= resolution;
canvas.width = Math.ceil(crop.width);
canvas.height = Math.ceil(crop.height);
context.save();
context.globalCompositeOperation = 'copy';
context.drawImage(
texture.baseTexture.getDrawableSource(),
crop.x,
crop.y,
crop.width,
crop.height,
0,
0,
crop.width,
crop.height
);
context.restore();
var rgbValues = hex2rgb(color);
var r = rgbValues[0];
var g = rgbValues[1];
var b = rgbValues[2];
var pixelData = context.getImageData(0, 0, crop.width, crop.height);
var pixels = pixelData.data;
for (var i = 0; i < pixels.length; i += 4)
{
pixels[i + 0] *= r;
pixels[i + 1] *= g;
pixels[i + 2] *= b;
}
context.putImageData(pixelData, 0, 0);
},
/**
* Rounds the specified color according to the canvasUtils.cacheStepsPerColorChannel.
*
* @memberof PIXI.canvasUtils
* @param {number} color - the color to round, should be a hex color
* @return {number} The rounded color.
*/
roundColor: function (color) {
var step = canvasUtils.cacheStepsPerColorChannel;
var rgbValues = hex2rgb(color);
rgbValues[0] = Math.min(255, (rgbValues[0] / step) * step);
rgbValues[1] = Math.min(255, (rgbValues[1] / step) * step);
rgbValues[2] = Math.min(255, (rgbValues[2] / step) * step);
return rgb2hex(rgbValues);
},
/**
* Number of steps which will be used as a cap when rounding colors.
*
* @memberof PIXI.canvasUtils
* @type {number}
*/
cacheStepsPerColorChannel: 8,
/**
* Tint cache boolean flag.
*
* @memberof PIXI.canvasUtils
* @type {boolean}
*/
convertTintToImage: false,
/**
* Whether or not the Canvas BlendModes are supported, consequently the ability to tint using the multiply method.
*
* @memberof PIXI.canvasUtils
* @type {boolean}
*/
canUseMultiply: canUseNewCanvasBlendModes(),
/**
* The tinting method that will be used.
*
* @memberof PIXI.canvasUtils
* @type {Function}
*/
tintMethod: function () { // jslint-disable no-empty-function
},
};
canvasUtils.tintMethod = canvasUtils.canUseMultiply ? canvasUtils.tintWithMultiply : canvasUtils.tintWithPerPixel;
// Reference to Renderer.create static function
var parentCreate = Renderer.create;
/**
* Override the Renderer.create to fallback to use CanvasRenderer.
* Also supports forceCanvas option with Application or autoDetectRenderer.
* @private
*/
Renderer.create = function create(options)
{
var forceCanvas = options && options.forceCanvas;
if (!forceCanvas)
{
try
{
return parentCreate(options);
}
catch (err)
{
// swallow WebGL-unsupported error
}
}
return new CanvasRenderer(options);
};
/**
* Get the drawable source, such as HTMLCanvasElement or HTMLImageElement suitable
* for rendering with CanvasRenderer. Provided by **@pixi/canvas-renderer** package.
* @method getDrawableSource
* @memberof PIXI.BaseTexture#
* @return {PIXI.ICanvasImageSource} Source to render with CanvasRenderer
*/
BaseTexture.prototype.getDrawableSource = function getDrawableSource()
{
var resource = this.resource;
return resource ? (resource.bitmap || resource.source) : this.source;
};
/*!
* @pixi/canvas-mesh - v5.2.1
* Compiled Tue, 04 Feb 2020 21:48:29 UTC
*
* @pixi/canvas-mesh is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
*/
/**
* Renderer dedicated to meshes.
*
* @class
* @protected
* @memberof PIXI
*/
var CanvasMeshRenderer = function CanvasMeshRenderer(renderer)
{
this.renderer = renderer;
};
/**
* Renders the Mesh
*
* @param {PIXI.Mesh} mesh - the Mesh to render
*/
CanvasMeshRenderer.prototype.render = function render (mesh)
{
var renderer = this.renderer;
var context = renderer.context;
var transform = mesh.worldTransform;
var res = renderer.resolution;
if (mesh.roundPixels)
{
context.setTransform(
transform.a * res,
transform.b * res,
transform.c * res,
transform.d * res,
(transform.tx * res) | 0,
(transform.ty * res) | 0
);
}
else
{
context.setTransform(
transform.a * res,
transform.b * res,
transform.c * res,
transform.d * res,
transform.tx * res,
transform.ty * res
);
}
renderer.context.globalAlpha = mesh.worldAlpha;
renderer.setBlendMode(mesh.blendMode);
if (mesh.drawMode !== exports.DRAW_MODES.TRIANGLES)
{
this._renderTriangleMesh(mesh);
}
else
{
this._renderTriangles(mesh);
}
};
/**
* Draws the object in Triangle Mesh mode
*
* @private
* @param {PIXI.Mesh} mesh - the Mesh to render
*/
CanvasMeshRenderer.prototype._renderTriangleMesh = function _renderTriangleMesh (mesh)
{
// draw triangles!!
var length = mesh.geometry.buffers[0].data.length;
for (var i = 0; i < length - 2; i++)
{
// draw some triangles!
var index = i * 2;
this._renderDrawTriangle(mesh, index, (index + 2), (index + 4));
}
};
/**
* Draws the object in triangle mode using canvas
*
* @private
* @param {PIXI.Mesh} mesh - the current mesh
*/
CanvasMeshRenderer.prototype._renderTriangles = function _renderTriangles (mesh)
{
// draw triangles!!
var indices = mesh.geometry.getIndex().data;
var length = indices.length;
for (var i = 0; i < length; i += 3)
{
// draw some triangles!
var index0 = indices[i] * 2;
var index1 = indices[i + 1] * 2;
var index2 = indices[i + 2] * 2;
this._renderDrawTriangle(mesh, index0, index1, index2);
}
};
/**
* Draws one of the triangles that from the Mesh
*
* @private
* @param {PIXI.Mesh} mesh - the current mesh
* @param {number} index0 - the index of the first vertex
* @param {number} index1 - the index of the second vertex
* @param {number} index2 - the index of the third vertex
*/
CanvasMeshRenderer.prototype._renderDrawTriangle = function _renderDrawTriangle (mesh, index0, index1, index2)
{
var context = this.renderer.context;
var vertices = mesh.geometry.buffers[0].data;
var uvs = mesh.uvs;
var texture = mesh.texture;
if (!texture.valid)
{
return;
}
var base = texture.baseTexture;
var textureSource = base.getDrawableSource();
var textureWidth = base.width;
var textureHeight = base.height;
var u0 = uvs[index0] * base.width;
var u1 = uvs[index1] * base.width;
var u2 = uvs[index2] * base.width;
var v0 = uvs[index0 + 1] * base.height;
var v1 = uvs[index1 + 1] * base.height;
var v2 = uvs[index2 + 1] * base.height;
var x0 = vertices[index0];
var x1 = vertices[index1];
var x2 = vertices[index2];
var y0 = vertices[index0 + 1];
var y1 = vertices[index1 + 1];
var y2 = vertices[index2 + 1];
var canvasPadding = mesh.canvasPadding / this.renderer.resolution;
if (canvasPadding > 0)
{
var paddingX = canvasPadding / Math.abs(mesh.worldTransform.a);
var paddingY = canvasPadding / Math.abs(mesh.worldTransform.d);
var centerX = (x0 + x1 + x2) / 3;
var centerY = (y0 + y1 + y2) / 3;
var normX = x0 - centerX;
var normY = y0 - centerY;
var dist = Math.sqrt((normX * normX) + (normY * normY));
x0 = centerX + ((normX / dist) * (dist + paddingX));
y0 = centerY + ((normY / dist) * (dist + paddingY));
//
normX = x1 - centerX;
normY = y1 - centerY;
dist = Math.sqrt((normX * normX) + (normY * normY));
x1 = centerX + ((normX / dist) * (dist + paddingX));
y1 = centerY + ((normY / dist) * (dist + paddingY));
normX = x2 - centerX;
normY = y2 - centerY;
dist = Math.sqrt((normX * normX) + (normY * normY));
x2 = centerX + ((normX / dist) * (dist + paddingX));
y2 = centerY + ((normY / dist) * (dist + paddingY));
}
context.save();
context.beginPath();
context.moveTo(x0, y0);
context.lineTo(x1, y1);
context.lineTo(x2, y2);
context.closePath();
context.clip();
// Compute matrix transform
var delta = (u0 * v1) + (v0 * u2) + (u1 * v2) - (v1 * u2) - (v0 * u1) - (u0 * v2);
var deltaA = (x0 * v1) + (v0 * x2) + (x1 * v2) - (v1 * x2) - (v0 * x1) - (x0 * v2);
var deltaB = (u0 * x1) + (x0 * u2) + (u1 * x2) - (x1 * u2) - (x0 * u1) - (u0 * x2);
var deltaC = (u0 * v1 * x2) + (v0 * x1 * u2) + (x0 * u1 * v2) - (x0 * v1 * u2) - (v0 * u1 * x2) - (u0 * x1 * v2);
var deltaD = (y0 * v1) + (v0 * y2) + (y1 * v2) - (v1 * y2) - (v0 * y1) - (y0 * v2);
var deltaE = (u0 * y1) + (y0 * u2) + (u1 * y2) - (y1 * u2) - (y0 * u1) - (u0 * y2);
var deltaF = (u0 * v1 * y2) + (v0 * y1 * u2) + (y0 * u1 * v2) - (y0 * v1 * u2) - (v0 * u1 * y2) - (u0 * y1 * v2);
context.transform(
deltaA / delta,
deltaD / delta,
deltaB / delta,
deltaE / delta,
deltaC / delta,
deltaF / delta
);
context.drawImage(
textureSource,
0,
0,
textureWidth * base.resolution,
textureHeight * base.resolution,
0,
0,
textureWidth,
textureHeight
);
context.restore();
this.renderer.invalidateBlendMode();
};
/**
* Renders a flat Mesh
*
* @private
* @param {PIXI.Mesh} mesh - The Mesh to render
*/
CanvasMeshRenderer.prototype.renderMeshFlat = function renderMeshFlat (mesh)
{
var context = this.renderer.context;
var vertices = mesh.geometry.getBuffer('aVertexPosition').data;
var length = vertices.length / 2;
// this.count++;
context.beginPath();
for (var i = 1; i < length - 2; ++i)
{
// draw some triangles!
var index = i * 2;
var x0 = vertices[index];
var y0 = vertices[index + 1];
var x1 = vertices[index + 2];
var y1 = vertices[index + 3];
var x2 = vertices[index + 4];
var y2 = vertices[index + 5];
context.moveTo(x0, y0);
context.lineTo(x1, y1);
context.lineTo(x2, y2);
}
context.fillStyle = '#FF0000';
context.fill();
context.closePath();
};
/**
* destroy the the renderer.
*
*/
CanvasMeshRenderer.prototype.destroy = function destroy ()
{
this.renderer = null;
};
/**
* Default `canvasPadding` for canvas-based Mesh rendering.
*
* @see PIXI.Mesh2d#canvasPadding
* @static
* @name MESH_CANVAS_PADDING
* @memberof PIXI.settings
* @type {number}
* @default 0
*/
settings.MESH_CANVAS_PADDING = 0;
/**
* Renders the mesh using the Canvas renderer
*
* @protected
* @method render
* @memberof PIXI.MeshMaterial#
* @param {PIXI.CanvasRenderer} renderer - The canvas renderer.
* @param {PIXI.Mesh} mesh - Mesh to render.
*/
MeshMaterial.prototype._renderCanvas = function _renderCanvas(renderer, mesh)
{
renderer.plugins.mesh.render(mesh);
};
/**
* Cached tint value so we can tell when the tint is changed.
* @memberof PIXI.NineSlicePlane#
* @member {number} _cachedTint
* @protected
*/
NineSlicePlane.prototype._cachedTint = 0xFFFFFF;
/**
* Cached tinted texture.
* @memberof PIXI.NineSlicePlane#
* @member {HTMLCanvasElement} _tintedCanvas
* @protected
*/
NineSlicePlane.prototype._tintedCanvas = null;
/**
* Temporary storage for canvas source coords
* @memberof PIXI.NineSlicePlane#
* @member {number[]} _canvasUvs
* @private
*/
NineSlicePlane.prototype._canvasUvs = null;
/**
* Renders the object using the Canvas renderer
*
* @private
* @method _renderCanvas
* @memberof PIXI.NineSlicePlane#
* @param {PIXI.CanvasRenderer} renderer - The canvas renderer to render with.
*/
NineSlicePlane.prototype._renderCanvas = function _renderCanvas(renderer)
{
var context = renderer.context;
var transform = this.worldTransform;
var res = renderer.resolution;
var isTinted = this.tint !== 0xFFFFFF;
var texture = this.texture;
// Work out tinting
if (isTinted)
{
if (this._cachedTint !== this.tint)
{
// Tint has changed, need to update the tinted texture and use that instead
this._cachedTint = this.tint;
this._tintedCanvas = canvasUtils.getTintedCanvas(this, this.tint);
}
}
var textureSource = !isTinted ? texture.baseTexture.getDrawableSource() : this._tintedCanvas;
if (!this._canvasUvs)
{
this._canvasUvs = [0, 0, 0, 0, 0, 0, 0, 0];
}
var vertices = this.vertices;
var uvs = this._canvasUvs;
var u0 = isTinted ? 0 : texture.frame.x;
var v0 = isTinted ? 0 : texture.frame.y;
var u1 = u0 + texture.frame.width;
var v1 = v0 + texture.frame.height;
uvs[0] = u0;
uvs[1] = u0 + this._leftWidth;
uvs[2] = u1 - this._rightWidth;
uvs[3] = u1;
uvs[4] = v0;
uvs[5] = v0 + this._topHeight;
uvs[6] = v1 - this._bottomHeight;
uvs[7] = v1;
for (var i = 0; i < 8; i++)
{
uvs[i] *= texture.baseTexture.resolution;
}
context.globalAlpha = this.worldAlpha;
renderer.setBlendMode(this.blendMode);
if (this.roundPixels)
{
context.setTransform(
transform.a * res,
transform.b * res,
transform.c * res,
transform.d * res,
(transform.tx * res) | 0,
(transform.ty * res) | 0
);
}
else
{
context.setTransform(
transform.a * res,
transform.b * res,
transform.c * res,
transform.d * res,
transform.tx * res,
transform.ty * res
);
}
for (var row = 0; row < 3; row++)
{
for (var col = 0; col < 3; col++)
{
var ind = (col * 2) + (row * 8);
var sw = Math.max(1, uvs[col + 1] - uvs[col]);
var sh = Math.max(1, uvs[row + 5] - uvs[row + 4]);
var dw = Math.max(1, vertices[ind + 10] - vertices[ind]);
var dh = Math.max(1, vertices[ind + 11] - vertices[ind + 1]);
context.drawImage(textureSource, uvs[col], uvs[row + 4], sw, sh,
vertices[ind], vertices[ind + 1], dw, dh);
}
}
};
/**
* Renders the object using the Canvas renderer
*
* @private
* @method _renderCanvas
* @memberof PIXI.Mesh#
* @param {PIXI.CanvasRenderer} renderer - The canvas renderer.
*/
Mesh.prototype._renderCanvas = function _renderCanvas(renderer)
{
if (this.shader.uvMatrix)
{
this.shader.uvMatrix.update();
this.calculateUvs();
}
this.material._renderCanvas(renderer, this);
};
// IMPORTANT: Please do NOT use this as a precedent to use `settings` after the object is created
// this was merely created to completely decouple canvas from the base Mesh class and we are
// unable to add `canvasPadding` in the constructor anymore, as the case was for PixiJS v4.
/**
* Internal variable for `canvasPadding`.
*
* @private
* @memberof PIXI.Mesh
* @member {number}
* @default null
*/
Mesh.prototype._canvasPadding = null;
/**
* Triangles in canvas mode are automatically antialiased, use this value to force triangles
* to overlap a bit with each other. To set the global default, set {@link PIXI.settings.MESH_CANVAS_PADDING}
*
* @see PIXI.settings.MESH_CANVAS_PADDING
* @member {number} canvasPadding
* @memberof PIXI.SimpleMesh#
* @default 0
*/
Object.defineProperty(Mesh.prototype, 'canvasPadding', {
get: function get()
{
return this._canvasPadding !== null ? this._canvasPadding : settings.MESH_CANVAS_PADDING;
},
set: function set(value)
{
this._canvasPadding = value;
},
});
/**
* Renders the object using the Canvas renderer
*
* @private
* @method _renderCanvas
* @memberof PIXI.Mesh#
* @param {PIXI.CanvasRenderer} renderer - The canvas renderer.
*/
SimpleMesh.prototype._renderCanvas = function _renderCanvas(renderer)
{
if (this.autoUpdate)
{
this.geometry.getBuffer('aVertexPosition').update();
}
if (this.shader.update)
{
this.shader.update();
}
this.calculateUvs();
this.material._renderCanvas(renderer, this);
};
/**
* Renders the object using the Canvas renderer
*
* @protected
* @method _renderCanvas
* @memberof PIXI.Mesh#
* @param {PIXI.CanvasRenderer} renderer - The canvas renderer.
*/
SimpleRope.prototype._renderCanvas = function _renderCanvas(renderer)
{
if (this.autoUpdate
|| this.geometry.width !== this.shader.texture.height)
{
this.geometry.width = this.shader.texture.height;
this.geometry.update();
}
if (this.shader.update)
{
this.shader.update();
}
this.calculateUvs();
this.material._renderCanvas(renderer, this);
};
/*!
* @pixi/canvas-graphics - v5.2.1
* Compiled Tue, 04 Feb 2020 21:48:29 UTC
*
* @pixi/canvas-graphics is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
*/
/**
* @author Mat Groves
*
* Big thanks to the very clever Matt DesLauriers https://github.com/mattdesl/
* for creating the original PixiJS version!
* Also a thanks to https://github.com/bchevalier for tweaking the tint and alpha so that they
* now share 4 bytes on the vertex buffer
*
* Heavily inspired by LibGDX's CanvasGraphicsRenderer:
* https://github.com/libgdx/libgdx/blob/1.0.0/gdx/src/com/badlogic/gdx/graphics/glutils/ShapeRenderer.java
*/
/**
* Renderer dedicated to drawing and batching graphics objects.
*
* @class
* @protected
* @memberof PIXI
*/
var CanvasGraphicsRenderer = function CanvasGraphicsRenderer(renderer)
{
this.renderer = renderer;
};
/**
* Renders a Graphics object to a canvas.
*
* @param {PIXI.Graphics} graphics - the actual graphics object to render
*/
CanvasGraphicsRenderer.prototype.render = function render (graphics)
{
var renderer = this.renderer;
var context = renderer.context;
var worldAlpha = graphics.worldAlpha;
var transform = graphics.transform.worldTransform;
var resolution = renderer.resolution;
context.setTransform(
transform.a * resolution,
transform.b * resolution,
transform.c * resolution,
transform.d * resolution,
transform.tx * resolution,
transform.ty * resolution
);
// update tint if graphics was dirty
if (graphics.canvasTintDirty !== graphics.geometry.dirty
|| graphics._prevTint !== graphics.tint)
{
this.updateGraphicsTint(graphics);
}
renderer.setBlendMode(graphics.blendMode);
var graphicsData = graphics.geometry.graphicsData;
for (var i = 0; i < graphicsData.length; i++)
{
var data = graphicsData[i];
var shape = data.shape;
var fillStyle = data.fillStyle;
var lineStyle = data.lineStyle;
var fillColor = data._fillTint;
var lineColor = data._lineTint;
context.lineWidth = lineStyle.width;
if (data.type === exports.SHAPES.POLY)
{
context.beginPath();
var points = shape.points;
var holes = data.holes;
var outerArea = (void 0);
var innerArea = (void 0);
var px = (void 0);
var py = (void 0);
context.moveTo(points[0], points[1]);
for (var j = 2; j < points.length; j += 2)
{
context.lineTo(points[j], points[j + 1]);
}
if (shape.closeStroke)
{
context.closePath();
}
if (holes.length > 0)
{
outerArea = 0;
px = points[0];
py = points[1];
for (var j$1 = 2; j$1 + 2 < points.length; j$1 += 2)
{
outerArea += ((points[j$1] - px) * (points[j$1 + 3] - py))
- ((points[j$1 + 2] - px) * (points[j$1 + 1] - py));
}
for (var k = 0; k < holes.length; k++)
{
points = holes[k].shape.points;
if (!points)
{
continue;
}
innerArea = 0;
px = points[0];
py = points[1];
for (var j$2 = 2; j$2 + 2 < points.length; j$2 += 2)
{
innerArea += ((points[j$2] - px) * (points[j$2 + 3] - py))
- ((points[j$2 + 2] - px) * (points[j$2 + 1] - py));
}
if (innerArea * outerArea < 0)
{
context.moveTo(points[0], points[1]);
for (var j$3 = 2; j$3 < points.length; j$3 += 2)
{
context.lineTo(points[j$3], points[j$3 + 1]);
}
}
else
{
context.moveTo(points[points.length - 2], points[points.length - 1]);
for (var j$4 = points.length - 4; j$4 >= 0; j$4 -= 2)
{
context.lineTo(points[j$4], points[j$4 + 1]);
}
}
if (holes[k].shape.closeStroke)
{
context.closePath();
}
}
}
if (fillStyle.visible)
{
context.globalAlpha = fillStyle.alpha * worldAlpha;
context.fillStyle = "#" + ((("00000" + ((fillColor | 0).toString(16)))).substr(-6));
context.fill();
}
if (lineStyle.visible)
{
context.globalAlpha = lineStyle.alpha * worldAlpha;
context.strokeStyle = "#" + ((("00000" + ((lineColor | 0).toString(16)))).substr(-6));
context.stroke();
}
}
else if (data.type === exports.SHAPES.RECT)
{
if (fillStyle.visible)
{
context.globalAlpha = fillStyle.alpha * worldAlpha;
context.fillStyle = "#" + ((("00000" + ((fillColor | 0).toString(16)))).substr(-6));
context.fillRect(shape.x, shape.y, shape.width, shape.height);
}
if (lineStyle.visible)
{
context.globalAlpha = lineStyle.alpha * worldAlpha;
context.strokeStyle = "#" + ((("00000" + ((lineColor | 0).toString(16)))).substr(-6));
context.strokeRect(shape.x, shape.y, shape.width, shape.height);
}
}
else if (data.type === exports.SHAPES.CIRC)
{
// TODO - need to be Undefined!
context.beginPath();
context.arc(shape.x, shape.y, shape.radius, 0, 2 * Math.PI);
context.closePath();
if (fillStyle.visible)
{
context.globalAlpha = fillStyle.alpha * worldAlpha;
context.fillStyle = "#" + ((("00000" + ((fillColor | 0).toString(16)))).substr(-6));
context.fill();
}
if (lineStyle.visible)
{
context.globalAlpha = lineStyle.alpha * worldAlpha;
context.strokeStyle = "#" + ((("00000" + ((lineColor | 0).toString(16)))).substr(-6));
context.stroke();
}
}
else if (data.type === exports.SHAPES.ELIP)
{
// ellipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas
var w = shape.width * 2;
var h = shape.height * 2;
var x = shape.x - (w / 2);
var y = shape.y - (h / 2);
context.beginPath();
var kappa = 0.5522848;
var ox = (w / 2) * kappa; // control point offset horizontal
var oy = (h / 2) * kappa; // control point offset vertical
var xe = x + w; // x-end
var ye = y + h; // y-end
var xm = x + (w / 2); // x-middle
var ym = y + (h / 2); // y-middle
context.moveTo(x, ym);
context.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y);
context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);
context.closePath();
if (fillStyle.visible)
{
context.globalAlpha = fillStyle.alpha * worldAlpha;
context.fillStyle = "#" + ((("00000" + ((fillColor | 0).toString(16)))).substr(-6));
context.fill();
}
if (lineStyle.visible)
{
context.globalAlpha = lineStyle.alpha * worldAlpha;
context.strokeStyle = "#" + ((("00000" + ((lineColor | 0).toString(16)))).substr(-6));
context.stroke();
}
}
else if (data.type === exports.SHAPES.RREC)
{
var rx = shape.x;
var ry = shape.y;
var width = shape.width;
var height = shape.height;
var radius = shape.radius;
var maxRadius = Math.min(width, height) / 2 | 0;
radius = radius > maxRadius ? maxRadius : radius;
context.beginPath();
context.moveTo(rx, ry + radius);
context.lineTo(rx, ry + height - radius);
context.quadraticCurveTo(rx, ry + height, rx + radius, ry + height);
context.lineTo(rx + width - radius, ry + height);
context.quadraticCurveTo(rx + width, ry + height, rx + width, ry + height - radius);
context.lineTo(rx + width, ry + radius);
context.quadraticCurveTo(rx + width, ry, rx + width - radius, ry);
context.lineTo(rx + radius, ry);
context.quadraticCurveTo(rx, ry, rx, ry + radius);
context.closePath();
if (fillStyle.visible)
{
context.globalAlpha = fillStyle.alpha * worldAlpha;
context.fillStyle = "#" + ((("00000" + ((fillColor | 0).toString(16)))).substr(-6));
context.fill();
}
if (lineStyle.visible)
{
context.globalAlpha = lineStyle.alpha * worldAlpha;
context.strokeStyle = "#" + ((("00000" + ((lineColor | 0).toString(16)))).substr(-6));
context.stroke();
}
}
}
};
/**
* Updates the tint of a graphics object
*
* @protected
* @param {PIXI.Graphics} graphics - the graphics that will have its tint updated
*/
CanvasGraphicsRenderer.prototype.updateGraphicsTint = function updateGraphicsTint (graphics)
{
graphics._prevTint = graphics.tint;
graphics.canvasTintDirty = graphics.geometry.dirty;
var tintR = ((graphics.tint >> 16) & 0xFF) / 255;
var tintG = ((graphics.tint >> 8) & 0xFF) / 255;
var tintB = (graphics.tint & 0xFF) / 255;
var graphicsData = graphics.geometry.graphicsData;
for (var i = 0; i < graphicsData.length; ++i)
{
var data = graphicsData[i];
var fillColor = data.fillStyle.color | 0;
var lineColor = data.lineStyle.color | 0;
// super inline, cos optimization :)
data._fillTint = (
(((fillColor >> 16) & 0xFF) / 255 * tintR * 255 << 16)
+ (((fillColor >> 8) & 0xFF) / 255 * tintG * 255 << 8)
+ (((fillColor & 0xFF) / 255) * tintB * 255)
);
data._lineTint = (
(((lineColor >> 16) & 0xFF) / 255 * tintR * 255 << 16)
+ (((lineColor >> 8) & 0xFF) / 255 * tintG * 255 << 8)
+ (((lineColor & 0xFF) / 255) * tintB * 255)
);
}
};
/**
* destroy graphics object
*
*/
CanvasGraphicsRenderer.prototype.destroy = function destroy ()
{
this.renderer = null;
};
var canvasRenderer;
var tempMatrix$1 = new Matrix();
/**
* Generates a canvas texture. Only available with **pixi.js-legacy** bundle
* or the **@pixi/canvas-graphics** package.
* @method generateCanvasTexture
* @memberof PIXI.Graphics#
* @param {number} scaleMode - The scale mode of the texture.
* @param {number} resolution - The resolution of the texture.
* @return {PIXI.Texture} The new texture.
*/
Graphics.prototype.generateCanvasTexture = function generateCanvasTexture(scaleMode, resolution)
{
if ( resolution === void 0 ) { resolution = 1; }
var bounds = this.getLocalBounds();
var canvasBuffer = RenderTexture.create(bounds.width, bounds.height, scaleMode, resolution);
if (!canvasRenderer)
{
canvasRenderer = new CanvasRenderer();
}
this.transform.updateLocalTransform();
this.transform.localTransform.copyTo(tempMatrix$1);
tempMatrix$1.invert();
tempMatrix$1.tx -= bounds.x;
tempMatrix$1.ty -= bounds.y;
canvasRenderer.render(this, canvasBuffer, true, tempMatrix$1);
var texture = Texture.from(canvasBuffer.baseTexture._canvasRenderTarget.canvas, {
scaleMode: scaleMode,
});
texture.baseTexture.resolution = resolution;
texture.baseTexture.update();
return texture;
};
Graphics.prototype.cachedGraphicsData = [];
/**
* Renders the object using the Canvas renderer
*
* @method _renderCanvas
* @memberof PIXI.Graphics#
* @private
* @param {PIXI.CanvasRenderer} renderer - The renderer
*/
Graphics.prototype._renderCanvas = function _renderCanvas(renderer)
{
if (this.isMask === true)
{
return;
}
this.finishPoly();
renderer.plugins.graphics.render(this);
};
/*!
* @pixi/canvas-sprite - v5.2.1
* Compiled Tue, 04 Feb 2020 21:48:29 UTC
*
* @pixi/canvas-sprite is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
*/
var canvasRenderWorldTransform = new Matrix();
/**
* Types that can be passed to drawImage
* @typedef {HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | ImageBitmap} ICanvasImageSource
* @memberof PIXI
*/
/**
* @author Mat Groves
*
* Big thanks to the very clever Matt DesLauriers https://github.com/mattdesl/
* for creating the original PixiJS version!
* Also a thanks to https://github.com/bchevalier for tweaking the tint and alpha so that they now
* share 4 bytes on the vertex buffer
*
* Heavily inspired by LibGDX's CanvasSpriteRenderer:
* https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/g2d/CanvasSpriteRenderer.java
*/
/**
* Renderer dedicated to drawing and batching sprites.
*
* @class
* @protected
* @memberof PIXI
*/
var CanvasSpriteRenderer = function CanvasSpriteRenderer(renderer)
{
this.renderer = renderer;
};
/**
* Renders the sprite object.
*
* @param {PIXI.Sprite} sprite - the sprite to render when using this spritebatch
*/
CanvasSpriteRenderer.prototype.render = function render (sprite)
{
var texture = sprite._texture;
var renderer = this.renderer;
var context = renderer.context;
var width = texture._frame.width;
var height = texture._frame.height;
var wt = sprite.transform.worldTransform;
var dx = 0;
var dy = 0;
var source = texture.baseTexture.getDrawableSource();
if (texture.orig.width <= 0 || texture.orig.height <= 0 || !source)
{
return;
}
if (!texture.valid)
{
return;
}
renderer.setBlendMode(sprite.blendMode, true);
renderer.context.globalAlpha = sprite.worldAlpha;
// If smoothingEnabled is supported and we need to change the smoothing property for sprite texture
var smoothingEnabled = texture.baseTexture.scaleMode === exports.SCALE_MODES.LINEAR;
if (renderer.smoothProperty && renderer.context[renderer.smoothProperty] !== smoothingEnabled)
{
context[renderer.smoothProperty] = smoothingEnabled;
}
if (texture.trim)
{
dx = (texture.trim.width / 2) + texture.trim.x - (sprite.anchor.x * texture.orig.width);
dy = (texture.trim.height / 2) + texture.trim.y - (sprite.anchor.y * texture.orig.height);
}
else
{
dx = (0.5 - sprite.anchor.x) * texture.orig.width;
dy = (0.5 - sprite.anchor.y) * texture.orig.height;
}
if (texture.rotate)
{
wt.copyTo(canvasRenderWorldTransform);
wt = canvasRenderWorldTransform;
groupD8.matrixAppendRotationInv(wt, texture.rotate, dx, dy);
// the anchor has already been applied above, so lets set it to zero
dx = 0;
dy = 0;
}
dx -= width / 2;
dy -= height / 2;
// Allow for pixel rounding
if (sprite.roundPixels)
{
renderer.context.setTransform(
wt.a,
wt.b,
wt.c,
wt.d,
(wt.tx * renderer.resolution) | 0,
(wt.ty * renderer.resolution) | 0
);
dx = dx | 0;
dy = dy | 0;
}
else
{
renderer.context.setTransform(
wt.a,
wt.b,
wt.c,
wt.d,
wt.tx * renderer.resolution,
wt.ty * renderer.resolution
);
}
var resolution = texture.baseTexture.resolution;
var outerBlend = renderer._outerBlend;
if (outerBlend)
{
context.save();
context.beginPath();
context.rect(
dx * renderer.resolution,
dy * renderer.resolution,
width * renderer.resolution,
height * renderer.resolution
);
context.clip();
}
if (sprite.tint !== 0xFFFFFF)
{
if (sprite._cachedTint !== sprite.tint || sprite._tintedCanvas.tintId !== sprite._texture._updateID)
{
sprite._cachedTint = sprite.tint;
// TODO clean up caching - how to clean up the caches?
sprite._tintedCanvas = canvasUtils.getTintedCanvas(sprite, sprite.tint);
}
context.drawImage(
sprite._tintedCanvas,
0,
0,
Math.floor(width * resolution),
Math.floor(height * resolution),
Math.floor(dx * renderer.resolution),
Math.floor(dy * renderer.resolution),
Math.floor(width * renderer.resolution),
Math.floor(height * renderer.resolution)
);
}
else
{
context.drawImage(
source,
texture._frame.x * resolution,
texture._frame.y * resolution,
Math.floor(width * resolution),
Math.floor(height * resolution),
Math.floor(dx * renderer.resolution),
Math.floor(dy * renderer.resolution),
Math.floor(width * renderer.resolution),
Math.floor(height * renderer.resolution)
);
}
if (outerBlend)
{
context.restore();
}
// just in case, leaking outer blend here will be catastrophic!
renderer.setBlendMode(exports.BLEND_MODES.NORMAL);
};
/**
* destroy the sprite object.
*
*/
CanvasSpriteRenderer.prototype.destroy = function destroy ()
{
this.renderer = null;
};
/**
* Cached tinted texture.
* @memberof PIXI.Sprite#
* @member {HTMLCanvasElement} _tintedCanvas
* @protected
*/
Sprite.prototype._tintedCanvas = null;
/**
* Renders the object using the Canvas renderer
*
* @private
* @method _renderCanvas
* @memberof PIXI.Sprite#
* @param {PIXI.CanvasRenderer} renderer - The renderer
*/
Sprite.prototype._renderCanvas = function _renderCanvas(renderer)
{
renderer.plugins.sprite.render(this);
};
/*!
* @pixi/canvas-extract - v5.2.1
* Compiled Tue, 04 Feb 2020 21:48:29 UTC
*
* @pixi/canvas-extract is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
*/
var TEMP_RECT$1 = new Rectangle();
/**
* The extract manager provides functionality to export content from the renderers.
*
* An instance of this class is automatically created by default, and can be found at `renderer.plugins.extract`
*
* @class
* @memberof PIXI
*/
var CanvasExtract = function CanvasExtract(renderer)
{
this.renderer = renderer;
/**
* Collection of methods for extracting data (image, pixels, etc.) from a display object or render texture
*
* @member {PIXI.CanvasExtract} extract
* @memberof PIXI.CanvasRenderer#
* @see PIXI.CanvasExtract
*/
renderer.extract = this;
};
/**
* Will return a HTML Image of the target
*
* @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @param {string} [format] - Image format, e.g. "image/jpeg" or "image/webp".
* @param {number} [quality] - JPEG or Webp compression from 0 to 1. Default is 0.92.
* @return {HTMLImageElement} HTML Image of the target
*/
CanvasExtract.prototype.image = function image (target, format, quality)
{
var image = new Image();
image.src = this.base64(target, format, quality);
return image;
};
/**
* Will return a a base64 encoded string of this target. It works by calling
* `CanvasExtract.getCanvas` and then running toDataURL on that.
*
* @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @param {string} [format] - Image format, e.g. "image/jpeg" or "image/webp".
* @param {number} [quality] - JPEG or Webp compression from 0 to 1. Default is 0.92.
* @return {string} A base64 encoded string of the texture.
*/
CanvasExtract.prototype.base64 = function base64 (target, format, quality)
{
return this.canvas(target).toDataURL(format, quality);
};
/**
* Creates a Canvas element, renders this target to it and then returns it.
*
* @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @return {HTMLCanvasElement} A Canvas element with the texture rendered on.
*/
CanvasExtract.prototype.canvas = function canvas (target)
{
var renderer = this.renderer;
var context;
var resolution;
var frame;
var renderTexture;
if (target)
{
if (target instanceof RenderTexture)
{
renderTexture = target;
}
else
{
renderTexture = renderer.generateTexture(target);
}
}
if (renderTexture)
{
context = renderTexture.baseTexture._canvasRenderTarget.context;
resolution = renderTexture.baseTexture._canvasRenderTarget.resolution;
frame = renderTexture.frame;
}
else
{
context = renderer.rootContext;
resolution = renderer.resolution;
frame = TEMP_RECT$1;
frame.width = this.renderer.width;
frame.height = this.renderer.height;
}
var width = Math.floor((frame.width * resolution) + 1e-4);
var height = Math.floor((frame.height * resolution) + 1e-4);
var canvasBuffer = new CanvasRenderTarget(width, height, 1);
var canvasData = context.getImageData(frame.x * resolution, frame.y * resolution, width, height);
canvasBuffer.context.putImageData(canvasData, 0, 0);
// send the canvas back..
return canvasBuffer.canvas;
};
/**
* Will return a one-dimensional array containing the pixel data of the entire texture in RGBA
* order, with integer values between 0 and 255 (included).
*
* @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @return {Uint8ClampedArray} One-dimensional array containing the pixel data of the entire texture
*/
CanvasExtract.prototype.pixels = function pixels (target)
{
var renderer = this.renderer;
var context;
var resolution;
var frame;
var renderTexture;
if (target)
{
if (target instanceof RenderTexture)
{
renderTexture = target;
}
else
{
renderTexture = renderer.generateTexture(target);
}
}
if (renderTexture)
{
context = renderTexture.baseTexture._canvasRenderTarget.context;
resolution = renderTexture.baseTexture._canvasRenderTarget.resolution;
frame = renderTexture.frame;
}
else
{
context = renderer.rootContext;
frame = TEMP_RECT$1;
frame.width = renderer.width;
frame.height = renderer.height;
}
return context.getImageData(0, 0, frame.width * resolution, frame.height * resolution).data;
};
/**
* Destroys the extract
*
*/
CanvasExtract.prototype.destroy = function destroy ()
{
this.renderer.extract = null;
this.renderer = null;
};
/*!
* @pixi/canvas-prepare - v5.2.1
* Compiled Tue, 04 Feb 2020 21:48:29 UTC
*
* @pixi/canvas-prepare is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
*/
var CANVAS_START_SIZE = 16;
/**
* The prepare manager provides functionality to upload content to the GPU.
*
* This cannot be done directly for Canvas like in WebGL, but the effect can be achieved by drawing
* textures to an offline canvas. This draw call will force the texture to be moved onto the GPU.
*
* An instance of this class is automatically created by default, and can be found at `renderer.plugins.prepare`
*
* @class
* @extends PIXI.BasePrepare
* @memberof PIXI
*/
var CanvasPrepare = /*@__PURE__*/(function (BasePrepare) {
function CanvasPrepare(renderer)
{
BasePrepare.call(this, renderer);
this.uploadHookHelper = this;
/**
* An offline canvas to render textures to
* @type {HTMLCanvasElement}
* @private
*/
this.canvas = document.createElement('canvas');
this.canvas.width = CANVAS_START_SIZE;
this.canvas.height = CANVAS_START_SIZE;
/**
* The context to the canvas
* @type {CanvasRenderingContext2D}
* @private
*/
this.ctx = this.canvas.getContext('2d');
// Add textures to upload
this.registerUploadHook(uploadBaseTextures$1);
}
if ( BasePrepare ) { CanvasPrepare.__proto__ = BasePrepare; }
CanvasPrepare.prototype = Object.create( BasePrepare && BasePrepare.prototype );
CanvasPrepare.prototype.constructor = CanvasPrepare;
/**
* Destroys the plugin, don't use after this.
*
*/
CanvasPrepare.prototype.destroy = function destroy ()
{
BasePrepare.prototype.destroy.call(this);
this.ctx = null;
this.canvas = null;
};
return CanvasPrepare;
}(BasePrepare));
/**
* Built-in hook to upload PIXI.Texture objects to the GPU.
*
* @private
* @param {*} prepare - Instance of CanvasPrepare
* @param {*} item - Item to check
* @return {boolean} If item was uploaded.
*/
function uploadBaseTextures$1(prepare, item)
{
if (item instanceof BaseTexture)
{
var image = item.source;
// Sometimes images (like atlas images) report a size of zero, causing errors on windows phone.
// So if the width or height is equal to zero then use the canvas size
// Otherwise use whatever is smaller, the image dimensions or the canvas dimensions.
var imageWidth = image.width === 0 ? prepare.canvas.width : Math.min(prepare.canvas.width, image.width);
var imageHeight = image.height === 0 ? prepare.canvas.height : Math.min(prepare.canvas.height, image.height);
// Only a small subsections is required to be drawn to have the whole texture uploaded to the GPU
// A smaller draw can be faster.
prepare.ctx.drawImage(image, 0, 0, imageWidth, imageHeight, 0, 0, prepare.canvas.width, prepare.canvas.height);
return true;
}
return false;
}
/*!
* @pixi/canvas-sprite-tiling - v5.2.1
* Compiled Tue, 04 Feb 2020 21:48:29 UTC
*
* @pixi/canvas-sprite-tiling is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
*/
/**
* Renders the object using the Canvas renderer
*
* @protected
* @function _renderCanvas
* @memberof PIXI.TilingSprite#
* @param {PIXI.CanvasRenderer} renderer - a reference to the canvas renderer
*/
TilingSprite.prototype._renderCanvas = function _renderCanvas(renderer)
{
var texture = this._texture;
if (!texture.baseTexture.valid)
{
return;
}
var context = renderer.context;
var transform = this.worldTransform;
var resolution = renderer.resolution;
var baseTexture = texture.baseTexture;
var source = baseTexture.getDrawableSource();
var baseTextureResolution = baseTexture.resolution;
var modX = ((this.tilePosition.x / this.tileScale.x) % texture._frame.width) * baseTextureResolution;
var modY = ((this.tilePosition.y / this.tileScale.y) % texture._frame.height) * baseTextureResolution;
// create a nice shiny pattern!
if (this._textureID !== this._texture._updateID || this._cachedTint !== this.tint)
{
this._textureID = this._texture._updateID;
// cut an object from a spritesheet..
var tempCanvas = new CanvasRenderTarget(texture._frame.width,
texture._frame.height,
baseTextureResolution);
// Tint the tiling sprite
if (this.tint !== 0xFFFFFF)
{
this._tintedCanvas = canvasUtils.getTintedCanvas(this, this.tint);
tempCanvas.context.drawImage(this._tintedCanvas, 0, 0);
}
else
{
tempCanvas.context.drawImage(source,
-texture._frame.x * baseTextureResolution, -texture._frame.y * baseTextureResolution);
}
this._cachedTint = this.tint;
this._canvasPattern = tempCanvas.context.createPattern(tempCanvas.canvas, 'repeat');
}
// set context state..
context.globalAlpha = this.worldAlpha;
context.setTransform(transform.a * resolution,
transform.b * resolution,
transform.c * resolution,
transform.d * resolution,
transform.tx * resolution,
transform.ty * resolution);
renderer.setBlendMode(this.blendMode);
// fill the pattern!
context.fillStyle = this._canvasPattern;
// TODO - this should be rolled into the setTransform above..
context.scale(this.tileScale.x / baseTextureResolution, this.tileScale.y / baseTextureResolution);
var anchorX = this.anchor.x * -this._width;
var anchorY = this.anchor.y * -this._height;
if (this.uvRespectAnchor)
{
context.translate(modX, modY);
context.fillRect(-modX + anchorX, -modY + anchorY,
this._width / this.tileScale.x * baseTextureResolution,
this._height / this.tileScale.y * baseTextureResolution);
}
else
{
context.translate(modX + anchorX, modY + anchorY);
context.fillRect(-modX, -modY,
this._width / this.tileScale.x * baseTextureResolution,
this._height / this.tileScale.y * baseTextureResolution);
}
};
/*!
* @pixi/canvas-particles - v5.2.1
* Compiled Tue, 04 Feb 2020 21:48:29 UTC
*
* @pixi/canvas-particles is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
*/
/**
* Renders the object using the Canvas renderer
* @method renderCanvas
* @memberof PIXI.ParticleContainer#
* @private
* @param {PIXI.CanvasRenderer} renderer - a reference to the canvas renderer
*/
ParticleContainer.prototype.renderCanvas = function renderCanvas(renderer)
{
if (!this.visible || this.worldAlpha <= 0 || !this.children.length || !this.renderable)
{
return;
}
var context = renderer.context;
var transform = this.worldTransform;
var isRotated = true;
var positionX = 0;
var positionY = 0;
var finalWidth = 0;
var finalHeight = 0;
renderer.setBlendMode(this.blendMode);
context.globalAlpha = this.worldAlpha;
this.displayObjectUpdateTransform();
for (var i = 0; i < this.children.length; ++i)
{
var child = this.children[i];
if (!child.visible)
{
continue;
}
var frame = child._texture.frame;
context.globalAlpha = this.worldAlpha * child.alpha;
if (child.rotation % (Math.PI * 2) === 0)
{
// this is the fastest way to optimise! - if rotation is 0 then we can avoid any kind of setTransform call
if (isRotated)
{
context.setTransform(
transform.a,
transform.b,
transform.c,
transform.d,
transform.tx * renderer.resolution,
transform.ty * renderer.resolution
);
isRotated = false;
}
positionX = ((child.anchor.x) * (-frame.width * child.scale.x)) + child.position.x + 0.5;
positionY = ((child.anchor.y) * (-frame.height * child.scale.y)) + child.position.y + 0.5;
finalWidth = frame.width * child.scale.x;
finalHeight = frame.height * child.scale.y;
}
else
{
if (!isRotated)
{
isRotated = true;
}
child.displayObjectUpdateTransform();
var childTransform = child.worldTransform;
if (this.roundPixels)
{
context.setTransform(
childTransform.a,
childTransform.b,
childTransform.c,
childTransform.d,
(childTransform.tx * renderer.resolution) | 0,
(childTransform.ty * renderer.resolution) | 0
);
}
else
{
context.setTransform(
childTransform.a,
childTransform.b,
childTransform.c,
childTransform.d,
childTransform.tx * renderer.resolution,
childTransform.ty * renderer.resolution
);
}
positionX = ((child.anchor.x) * (-frame.width)) + 0.5;
positionY = ((child.anchor.y) * (-frame.height)) + 0.5;
finalWidth = frame.width;
finalHeight = frame.height;
}
var resolution = child._texture.baseTexture.resolution;
context.drawImage(
child._texture.baseTexture.getDrawableSource(),
frame.x * resolution,
frame.y * resolution,
frame.width * resolution,
frame.height * resolution,
positionX * renderer.resolution,
positionY * renderer.resolution,
finalWidth * renderer.resolution,
finalHeight * renderer.resolution
);
}
};
/*!
* @pixi/canvas-display - v5.2.1
* Compiled Tue, 04 Feb 2020 21:48:29 UTC
*
* @pixi/canvas-display is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
*/
/**
* To be overridden by the subclass
* @method _renderCanvas
* @memberof PIXI.Container#
* @protected
* @param {PIXI.CanvasRenderer} renderer - The renderer
*/
Container.prototype._renderCanvas = function _renderCanvas(renderer) // eslint-disable-line no-unused-vars
{
// this is where content itself gets rendered...
};
/**
* Renders the object using the Canvas renderer
* @method renderCanvas
* @memberof PIXI.Container#
* @param {PIXI.CanvasRenderer} renderer - The renderer
*/
Container.prototype.renderCanvas = function renderCanvas(renderer)
{
// if not visible or the alpha is 0 then no need to render this
if (!this.visible || this.worldAlpha <= 0 || !this.renderable)
{
return;
}
if (this._mask)
{
renderer.maskManager.pushMask(this._mask);
}
this._renderCanvas(renderer);
for (var i = 0, j = this.children.length; i < j; ++i)
{
this.children[i].renderCanvas(renderer);
}
if (this._mask)
{
renderer.maskManager.popMask(renderer);
}
};
/**
* Renders the object using the Canvas renderer
* @method renderCanvas
* @memberof PIXI.Container#
* @param {PIXI.CanvasRenderer} renderer - The renderer
*/
DisplayObject.prototype.renderCanvas = function renderCanvas(renderer) // eslint-disable-line no-unused-vars
{
// OVERWRITE;
};
/*!
* @pixi/canvas-text - v5.2.1
* Compiled Tue, 04 Feb 2020 21:48:29 UTC
*
* @pixi/canvas-text is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
*/
/**
* Renders the object using the Canvas renderer
*
* @method _renderCanvas
* @memberof PIXI.Text#
* @private
* @param {PIXI.CanvasRenderer} renderer - The renderer
*/
Text.prototype._renderCanvas = function _renderCanvas(renderer)
{
if (this._autoResolution && this._resolution !== renderer.resolution)
{
this._resolution = renderer.resolution;
this.dirty = true;
}
this.updateText(true);
Sprite.prototype._renderCanvas.call(this, renderer);
};
CanvasRenderer.registerPlugin('accessibility', AccessibilityManager);
CanvasRenderer.registerPlugin('extract', CanvasExtract);
CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer);
CanvasRenderer.registerPlugin('interaction', InteractionManager);
CanvasRenderer.registerPlugin('mesh', CanvasMeshRenderer);
CanvasRenderer.registerPlugin('prepare', CanvasPrepare);
CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer);
exports.AbstractBatchRenderer = AbstractBatchRenderer;
exports.AbstractRenderer = AbstractRenderer;
exports.AnimatedSprite = AnimatedSprite;
exports.AppLoaderPlugin = AppLoaderPlugin;
exports.Application = Application;
exports.Attribute = Attribute;
exports.BasePrepare = BasePrepare;
exports.BaseRenderTexture = BaseRenderTexture;
exports.BaseTexture = BaseTexture;
exports.BatchDrawCall = BatchDrawCall;
exports.BatchGeometry = BatchGeometry;
exports.BatchPluginFactory = BatchPluginFactory;
exports.BatchRenderer = BatchRenderer;
exports.BatchShaderGenerator = BatchShaderGenerator;
exports.BatchTextureArray = BatchTextureArray;
exports.BitmapFont = BitmapFont;
exports.BitmapFontData = BitmapFontData;
exports.BitmapFontLoader = BitmapFontLoader;
exports.BitmapText = BitmapText;
exports.Bounds = Bounds;
exports.Buffer = Buffer;
exports.CanvasExtract = CanvasExtract;
exports.CanvasGraphicsRenderer = CanvasGraphicsRenderer;
exports.CanvasMeshRenderer = CanvasMeshRenderer;
exports.CanvasPrepare = CanvasPrepare;
exports.CanvasRenderer = CanvasRenderer;
exports.CanvasSpriteRenderer = CanvasSpriteRenderer;
exports.Circle = Circle;
exports.Container = Container;
exports.CountLimiter = CountLimiter;
exports.DEG_TO_RAD = DEG_TO_RAD;
exports.DisplayObject = DisplayObject;
exports.Ellipse = Ellipse;
exports.Extract = Extract;
exports.FillStyle = FillStyle;
exports.Filter = Filter;
exports.FilterState = FilterState;
exports.Framebuffer = Framebuffer;
exports.GLFramebuffer = GLFramebuffer;
exports.GLProgram = GLProgram;
exports.GLTexture = GLTexture;
exports.GRAPHICS_CURVES = GRAPHICS_CURVES;
exports.Geometry = Geometry;
exports.Graphics = Graphics;
exports.GraphicsData = GraphicsData;
exports.GraphicsGeometry = GraphicsGeometry;
exports.IGLUniformData = IGLUniformData;
exports.LineStyle = LineStyle;
exports.Loader = Loader$1;
exports.LoaderResource = LoaderResource;
exports.MaskData = MaskData;
exports.Matrix = Matrix;
exports.Mesh = Mesh;
exports.MeshBatchUvs = MeshBatchUvs;
exports.MeshGeometry = MeshGeometry;
exports.MeshMaterial = MeshMaterial;
exports.NineSlicePlane = NineSlicePlane;
exports.ObjectRenderer = ObjectRenderer;
exports.ObservablePoint = ObservablePoint;
exports.PI_2 = PI_2;
exports.ParticleContainer = ParticleContainer;
exports.ParticleRenderer = ParticleRenderer;
exports.PlaneGeometry = PlaneGeometry;
exports.Point = Point;
exports.Polygon = Polygon;
exports.Prepare = Prepare;
exports.Program = Program;
exports.Quad = Quad;
exports.QuadUv = QuadUv;
exports.RAD_TO_DEG = RAD_TO_DEG;
exports.Rectangle = Rectangle;
exports.RenderTexture = RenderTexture;
exports.RenderTexturePool = RenderTexturePool;
exports.Renderer = Renderer;
exports.RopeGeometry = RopeGeometry;
exports.RoundedRectangle = RoundedRectangle;
exports.Runner = Runner;
exports.Shader = Shader;
exports.SimpleMesh = SimpleMesh;
exports.SimplePlane = SimplePlane;
exports.SimpleRope = SimpleRope;
exports.Sprite = Sprite;
exports.SpriteMaskFilter = SpriteMaskFilter;
exports.Spritesheet = Spritesheet;
exports.SpritesheetLoader = SpritesheetLoader;
exports.State = State;
exports.System = System;
exports.TEXT_GRADIENT = TEXT_GRADIENT;
exports.TemporaryDisplayObject = TemporaryDisplayObject;
exports.Text = Text;
exports.TextMetrics = TextMetrics;
exports.TextStyle = TextStyle;
exports.Texture = Texture;
exports.TextureLoader = TextureLoader;
exports.TextureMatrix = TextureMatrix;
exports.TextureUvs = TextureUvs;
exports.Ticker = Ticker;
exports.TickerPlugin = TickerPlugin;
exports.TilingSprite = TilingSprite;
exports.TilingSpriteRenderer = TilingSpriteRenderer;
exports.TimeLimiter = TimeLimiter;
exports.Transform = Transform;
exports.UniformGroup = UniformGroup;
exports.VERSION = VERSION$1;
exports.ViewableBuffer = ViewableBuffer;
exports.accessibility = accessibility_es;
exports.autoDetectRenderer = autoDetectRenderer;
exports.canvasUtils = canvasUtils;
exports.checkMaxIfStatementsInShader = checkMaxIfStatementsInShader;
exports.defaultFilterVertex = defaultFilter;
exports.defaultVertex = _default;
exports.filters = filters;
exports.graphicsUtils = index$2;
exports.groupD8 = groupD8;
exports.interaction = interaction_es;
exports.isMobile = isMobile$1;
exports.resources = index;
exports.settings = settings;
exports.systems = systems;
exports.useDeprecated = useDeprecated;
exports.utils = utils_es;
return exports;
}({}));
PIXI.useDeprecated();
//# sourceMappingURL=pixi-legacy.js.map